
모든 내부통신 허용 (ingress all allow)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-all-ingress
spec:
podSelector: {}
ingress:
- {} # 모든 정책 allow
policyTypes:
- Ingress
모든 내부통신 제한 (ingress all deny)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-ingress
spec:
podSelector: {} # ingress rule 이 존재하지 않음 = all deny
policyTypes:
- Ingress
모든 ingress/egress 통신 제한
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
spec:
podSelector: {}
policyTypes: # 다수의 policyType 에 대해, rule 이 존재하지 않음
- Ingress
- Egress
다수 NetworkPolicy rule 이 포함된 예시
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: my-policy
namespace: default
spec:
podSelector:
matchLabels:
name: my-pod
policyTypes:
- Egress
- Ingress
ingress:
- {} # inbound traffic all allow
egress:
- to: # 1. outbound rule
- podSelector:
matchLabels:
name: mysql
ports:
- protocol: TCP
port: 3306
- to: # 2. outbound rule
- podSelector:
matchLabels:
name: web
ports:
- protocol: TCP
port: 8080
- ports: # 3. outbound rule: kube-dns 사용 목적
- port: 53
protocol: UDP
- port: 53
protocol: TCP
https://kubernetes.io/ko/docs/concepts/services-networking/network-policies/