두 Namespace간 통신 허용

1 개요[ | ]

NetworkPolicy Namespace 셀렉터 - 두 Namespace간 통신 허용

2 시나리오[ | ]

새 NetworkPolicy 생성
  • 네임스페이스 space1space2에 pod들이 있다.
  • 네임스페이스 space1의 모든 pod들이, 네임스페이스 space2의 pod들로 가는 트래픽을 차단하는 NetworkPolicy np생성 (오는 트래픽에는 영향이 없어야 한다)
  • 단, TCP/UDP 53 포트로 가는 DNS 트래픽은 허용

3 실습[ | ]

$ vi np.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: np
  namespace: space1
spec:
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 53
      protocol: TCP
    - port: 53
      protocol: UDP
  - to:
     - namespaceSelector:
        matchLabels:
         kubernetes.io/metadata.name: space2
$ kubectl apply -f np.yaml 
networkpolicy.networking.k8s.io/np created
$ k -n space1 exec app1-0 -- curl -m 1 microservice1.space2.svc.cluster.local    
...
</html>
100   615  100   615    0     0  79365      0 --:--:-- --:--:-- --:--:-- 87857
$ k -n space1 exec app1-0 -- curl -m 1 microservice2.space2.svc.cluster.local
...
</html>
100   615  100   615    0     0  92718      0 --:--:-- --:--:-- --:--:--  100k
$ k -n space1 exec app1-0 -- nslookup tester.default.svc.cluster.local
Server:         10.96.0.10
...
Address: 10.100.186.10
$ k -n space1 exec app1-0 -- nslookup killercoda.com
Server:         10.96.0.10
...
Address: 2606:4700:20::681a:f6f
$ k -n space1 exec app1-0 -- curl -m 1 tester.default.svc.cluster.local
...
curl: (28) Connection timed out after 1000 milliseconds
command terminated with exit code 28
$ k -n space1 exec app1-0 -- curl -m 1 killercoda.com
...
curl: (28) Failed to connect to killercoda.com port 80 after 928 ms: Operation timed out
command terminated with exit code 28
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}