GithubHelp home page GithubHelp logo

doytsujin / kubernetes-network-policy-recipes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ahmetb/kubernetes-network-policy-recipes

0.0 1.0 0.0 1.08 MB

Example recipes for Kubernetes Network Policies that you can just copy paste

License: Apache License 2.0

kubernetes-network-policy-recipes's Introduction

You can get stuff like this You can get stuff like this with Network Policies...

Kubernetes Network Policy Recipes

This repository contains various use cases of Kubernetes Network Policies and sample YAML files to leverage in your setup. If you ever wondered how to drop/restrict traffic to applications running on Kubernetes, read on.

Easiest way to try out Network Policies is to create a new Google Kubernetes Engine cluster. Applying Network Policies on your existing cluster can disrupt the networking. At the time of writing, most cloud providers do not provide built-in network policy support.

If you are not familiar with Network Policies at all, I recommend reading my Securing Kubernetes Cluster Networking article first.

NetworkPolicy Crash Course

NetworkPolicies operate at layer 3 or 4 of OSI model (IP and port level). They are used to control the traffic in(ingress) and out(egress) of pods.

Here are some NetworkPolicies gotcha's

  • An empty selector will match everything. For example spec.podSelector: {} will apply the policy to all pods in the current namespace.

  • Selectors can only select Pods that are in the same namespace as the NetworkPolicies. Eg. spec.podSelector of an ingress rule can only select pods in the same namespace the NetworkPolicy is deployed to.

  • If no NetworkPolicies targets a pod, all traffic to and from the pod is allowed. In other words all traffic are allowed until a policy is applied.

  • There are no deny rules in NetworkPolicies. NetworkPolicies are deny by default allow explicitly. It's the same as saying "If you're not on the list you can't get in."

  • If a NetworkPolicies matches a pod but has a null rule, all traffic is blocked. Example of this is a "Deny all traffic policy".

spec:
  podSelector:
    matchLabels:
      ...
  ingress: []
  • Rules are chained together. NetworkPolicy are additive. If multiple NetworkPolicies are selecting a pod, their union is evaluated and applied to that pod.

Before you begin

I really recommend watching my KubeCon talk on Network Policies if you want to get a good understanding of this feature. It will help you understand this repo better.

Basics

Namespaces

Serving External Traffic

Advanced

Controlling Outbound (Egress) Traffic ๐Ÿ”ฅ๐Ÿ†•๐Ÿ”ฅ


Author

Created by Ahmet Alp Balkan (@ahmetb).

Copyright 2017, Google Inc. Distributed under Apache License Version 2.0 ,see LICENSE for details.

Disclaimer: This is not an official Google product.

Stargazers over time

kubernetes-network-policy-recipes's People

Contributors

ahmetb avatar ammaristotle avatar artturik avatar avinashdesireddy avatar bmcustodio avatar boredabdel avatar corentindy avatar ericyz avatar fmoctezuma avatar gre8t avatar hamzablm avatar j-zimnowoda avatar knabben avatar limoneren avatar mattfenwick avatar maxbischoff avatar mhobotpplnet avatar muse-sisay avatar pdecat avatar rk295 avatar shinerrs avatar shingon avatar sobngwi avatar tej-singh-rana avatar toqueteos avatar vtrduque avatar yamaszone avatar yanivpaz avatar zburgermeiszter avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.