> 文档中心 > k8s 网络策略

k8s 网络策略

支持基于calico的网络策略

apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata:  name: test-network-policy  namespace: default spec:  podSelector:    matchLabels:  #该参数为空则保护当前命名空间下所有pod      role: db  policyTypes:  - Ingress  #其它客户端进入流量  - Egress  #选中的pod出去的流量  ingress:  #ingress:   #- {} 允许所有入流量  - from:  #from可设置多个。    - ipBlock:  #定义可访问pod的IP段 cidr: 172.17.0.0/16   #在此网段内的可以访问被保护的pod except: - 172.17.1.0/24    - namespaceSelector: #定义可访问的ns matchLabels:   project: myproject      podSelector:  #在定义了ns的情况下同时定义可访问的pod matchLabels: #该参数为空则无label限制   role: frontend    - podSelector:  #定义可访问的pod matchLabels: #该参数为空则无label限制   role: frontend    ports:    - protocol: TCP      port: 6379 - from:   - ipBlock:cidr: 192.168.1.0/24   ports:   - protocol: TCP     port: 80 egress: - to:   - ipBlock:      cidr: 10.0.0.0/24   ports:   - protocol: TCP     port: 5978

狗狗宠物资料大全