运维八一 运维八一
首页
运维杂记
编程浅尝
周积跬步
专栏
生活
关于
收藏
  • 分类
  • 标签
  • 归档
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
      • Manifest
        • Cleanup
    • 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
  • 专栏
  • kubernetes-network-policy-recipes
lyndon
2024-02-26
目录

deny-all-non-whitelisted-traffic-in-the-namespace

# DENY all non-whitelisted traffic to a namespace

💡 Use Case: This is a fundamental policy, blocking all cross-pod networking other than the ones whitelisted via the other Network Policies you deploy.

Consider applying this manifest to any namespace you deploy workloads to (anything but kube-system).

💡 Best Practice: This policy will give you a default "deny all" functionality. This way, you can clearly identify which components have dependency on which components and deploy Network Policies which can be translated to dependency graphs between components.

Diagram of DENY all non-whitelisted traffic policy

# Manifest

kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  name: default-deny-all
  namespace: default
spec:
  podSelector: {}
  ingress: []
1
2
3
4
5
6
7
8

Note a few things about this manifest:

  • namespace: default deploy this policy to the default namespace.
  • podSelector: is empty, this means it will match all the pods. Therefore, the policy will be enforced to ALL pods in the default namespace .
  • There are no ingress rules specified. This causes incoming traffic to be dropped to the selected (=all) pods.
    • In this case, you can just omit the ingress field, or leave it empty like ingress:

Save this manifest to default-deny-all.yaml and apply:

$ kubectl apply -f default-deny-all.yaml
networkpolicy "default-deny-all" created
1
2

# Cleanup

kubectl delete networkpolicy default-deny-all
上次更新: 2024/02/26, 10:14:04
limit-traffic-to-an-application
deny-traffic-from-other-namespaces

← limit-traffic-to-an-application deny-traffic-from-other-namespaces→

最近更新
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
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式