运维八一 运维八一
首页
运维杂记
编程浅尝
周积跬步
专栏
生活
关于
收藏
  • 分类
  • 标签
  • 归档
Source (opens new window)

运维八一

运维,运维!
首页
运维杂记
编程浅尝
周积跬步
专栏
生活
关于
收藏
  • 分类
  • 标签
  • 归档
Source (opens new window)
  • Devops笔记

  • Kubernetes

  • 运维监控系统

  • go分布式爬虫

  • Linux性能优化

  • 夜莺(nightingale)开源观测平台

  • kubernetes-network-policy-recipes

    • create-cluster
    • deny-all-traffic-to-an-application
    • allow-all-traffic-to-an-application
    • limit-traffic-to-an-application
    • deny-all-non-whitelisted-traffic-in-the-namespace
    • deny-traffic-from-other-namespaces
    • allow-traffic-from-all-namespaces
    • allow-traffic-from-a-namespace
    • allow-traffic-from-some-pods-in-another-namespace
    • allow-external-traffic
    • allow-traffic-only-to-a-port
    • allowing-traffic-with-multiple-selectors
    • deny-egress-traffic-from-an-application
    • deny-all-non-whitelisted-traffic-from-the-namespace
    • deny-external-egress-traffic
    • README
      • NetworkPolicy Crash Course
        • Before you begin
        • Basics
        • Namespaces
        • Serving External Traffic
        • Advanced
        • Controlling Outbound (Egress) Traffic 🔥🆕🔥
        • Author
  • 专栏
  • kubernetes-network-policy-recipes
lyndon
2024-02-26
目录

README

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 (opens new window) 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 (opens new window) 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 (opens new window) 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: []
1
2
3
4
5
  • 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 (opens new window) if you want to get a good understanding of this feature. It will help you understand this repo better.

  • Create a cluster

# Basics

  • DENY all traffic to an application
  • LIMIT traffic to an application
  • ALLOW all traffic to an application

# Namespaces

  • DENY all non-whitelisted traffic in the current namespace
  • DENY all traffic from other namespaces (a.k.a. LIMIT access to the current namespace)
  • ALLOW traffic to an application from all namespaces
  • ALLOW all traffic from a namespace
  • ALLOW traffic from some pods in another namespace

# Serving External Traffic

  • ALLOW traffic from external clients

# Advanced

  • ALLOW traffic only to certain port numbers of an application
  • ALLOW traffic from apps using multiple selectors

# Controlling Outbound (Egress) Traffic 🔥🆕🔥

  • DENY egress traffic from an application
  • DENY all non-whitelisted egress traffic in a namespace
  • 🔜 LIMIT egress traffic from an application to some pods
  • 🔜 ALLOW traffic only to Pods in a namespace
  • LIMIT egress traffic to the cluster (DENY external egress traffic)

# Author

Created by Ahmet Alp Balkan (@ahmetb (opens new window)).

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

上次更新: 2024/02/26, 10:14:04
deny-external-egress-traffic

← deny-external-egress-traffic

最近更新
01
ctr和crictl显示镜像不一致
03-13
02
alpine镜像集成常用数据库客户端
03-13
03
create-cluster
02-26
更多文章>
Theme by Vdoing | Copyright © 2015-2024 op81.com
苏ICP备18041258号-2
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式