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

    allow-external-traffic

    # ALLOW traffic from external clients

    This Network Policy enables external clients from the public Internet directly or via a Load Balancer to access to the pod.

    Use Cases:

    • You need to expose the pods to the public Internet in a namespace denying all non-whitelisted traffic

    Diagram of ALLOW traffic from external clients policy

    # Example

    Run a web server and expose it to the internet with a Load Balancer:

    kubectl run web --image=nginx --labels="app=web" --port=80
    
    kubectl expose pod/web --type=LoadBalancer
    
    1
    2
    3

    Wait until an EXTERNAL-IP appears on kubectl get service output. Visit the http://[EXTERNAL-IP] on your browser and verify it is accessible.

    The following manifest allows traffic from all sources (both internal from the cluster and external). Save it to web-allow-external.yaml and apply to the cluster:

    kind: NetworkPolicy
    apiVersion: networking.k8s.io/v1
    metadata:
      name: web-allow-external
    spec:
      podSelector:
        matchLabels:
          app: web
      ingress:
      - {}
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    $ kubectl apply -f web-allow-external.yaml
    networkpolicy "web-allow-external" created
    
    1
    2

    Visit the http://[EXTERNAL-IP] on your browser again and verify it still works.

    # Remarks

    This manifest specifies one ingress rule for the app=web pods. Since it does not specify a particular podSelector or namespaceSelector, it allows traffic from all resources, including external.

    To restrict external access only to port 80, you can deploy an ingress rule such as:

      ingress:
      - ports:
        - port: 80
    
    1
    2
    3

    # Cleanup

    kubectl delete pod web
    kubectl delete service web
    kubectl delete networkpolicy web-allow-external
    
    上次更新: 2024/02/26, 10:14:04
    allow-traffic-from-some-pods-in-another-namespace
    allow-traffic-only-to-a-port

    ← allow-traffic-from-some-pods-in-another-namespace allow-traffic-only-to-a-port→

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