4.2. ovnkube-trace 실행
ovn-trace 를 실행하여 OVN 논리 네트워크 내에서 패킷 전달을 시뮬레이션합니다.
사전 요구 사항
-
OpenShift CLI(
oc)를 설치합니다. -
cluster-admin권한이 있는 사용자로 클러스터에 로그인합니다. -
로컬 호스트에
ovnkube-trace를 설치했습니다.
예: 배포된 Pod에서 DNS 확인이 작동하는지 테스트
이 예에서는 배포된 Pod에서 클러스터에서 실행되는 코어 DNS Pod로 DNS 확인을 테스트하는 방법을 보여줍니다.
프로세스
다음 명령을 입력하여 기본 네임스페이스에서 웹 서비스를 시작합니다.
$ oc run web --namespace=default --image=quay.io/openshifttest/nginx --labels="app=web" --expose --port=80openshift-dns네임스페이스에서 실행 중인 Pod를 나열합니다.oc get pods -n openshift-dns출력 예
NAME READY STATUS RESTARTS AGE dns-default-8s42x 2/2 Running 0 5h8m dns-default-mdw6r 2/2 Running 0 4h58m dns-default-p8t5h 2/2 Running 0 4h58m dns-default-rl6nk 2/2 Running 0 5h8m dns-default-xbgqx 2/2 Running 0 5h8m dns-default-zv8f6 2/2 Running 0 4h58m node-resolver-62jjb 1/1 Running 0 5h8m node-resolver-8z4cj 1/1 Running 0 4h59m node-resolver-bq244 1/1 Running 0 5h8m node-resolver-hc58n 1/1 Running 0 4h59m node-resolver-lm6z4 1/1 Running 0 5h8m node-resolver-zfx5k 1/1 Running 0 5h다음
ovnkube-trace명령을 실행하여 DNS 확인이 작동하는지 확인합니다.$ ./ovnkube-trace \ -src-namespace default \1 -src web \2 -dst-namespace openshift-dns \3 -dst dns-default-p8t5h \4 -udp -dst-port 53 \5 -loglevel 06 src&dst포드가 동일한 노드에 배치된 경우 출력 예ovn-trace source pod to destination pod indicates success from web to dns-default-p8t5h ovn-trace destination pod to source pod indicates success from dns-default-p8t5h to web ovs-appctl ofproto/trace source pod to destination pod indicates success from web to dns-default-p8t5h ovs-appctl ofproto/trace destination pod to source pod indicates success from dns-default-p8t5h to web ovn-detrace source pod to destination pod indicates success from web to dns-default-p8t5h ovn-detrace destination pod to source pod indicates success from dns-default-p8t5h to websrc&dst포드가 다른 노드에 배치된 경우 출력 예ovn-trace source pod to destination pod indicates success from web to dns-default-8s42x ovn-trace (remote) source pod to destination pod indicates success from web to dns-default-8s42x ovn-trace destination pod to source pod indicates success from dns-default-8s42x to web ovn-trace (remote) destination pod to source pod indicates success from dns-default-8s42x to web ovs-appctl ofproto/trace source pod to destination pod indicates success from web to dns-default-8s42x ovs-appctl ofproto/trace destination pod to source pod indicates success from dns-default-8s42x to web ovn-detrace source pod to destination pod indicates success from web to dns-default-8s42x ovn-detrace destination pod to source pod indicates success from dns-default-8s42x to webouput은 배포된 Pod에서 DNS 포트로의 성공 여부를 나타내며 다른 방향으로 돌아가고 있음을 나타냅니다. 따라서 웹 pod가 코어 DNS에서 DNS 확인을 수행하는 경우 UDP 포트 53에서 양방향 트래픽이 지원됩니다.
예를 들어 작동하지 않고 ovn-trace, proto/trace 및 ovn-detrace 의 ovs-appctl 을 가져오고 더 많은 디버그 유형 정보는 로그 수준을 2로 늘리고 다음과 같이 명령을 다시 실행합니다.
$ ./ovnkube-trace \
-src-namespace default \
-src web \
-dst-namespace openshift-dns \
-dst dns-default-467qw \
-udp -dst-port 53 \
-loglevel 2
이 증가된 로그 수준의 출력은 여기에 나열하기에는 너무 많습니다. 오류가 발생하면 이 명령의 출력에서 해당 트래픽을 삭제하는 흐름이 표시됩니다. 예를 들어 송신 또는 수신 네트워크 정책은 해당 트래픽을 허용하지 않는 클러스터에 구성할 수 있습니다.
예: 디버그 출력을 사용하여 구성된 기본 거부 확인
이 예에서는 Ingress 기본 거부 정책이 트래픽을 차단하는 디버그 출력을 사용하여 식별하는 방법을 보여줍니다.
프로세스
모든 네임스페이스의 모든 포드의 수신을
거부하도록 기본거부 정책을 정의하는 다음 YAML을 생성합니다. YAML을deny-by-default.yaml파일에 저장합니다.kind: NetworkPolicy apiVersion: networking.k8s.io/v1 metadata: name: deny-by-default namespace: default spec: podSelector: {} ingress: []다음 명령을 입력하여 정책을 적용합니다.
$ oc apply -f deny-by-default.yaml출력 예
networkpolicy.networking.k8s.io/deny-by-default created다음 명령을 입력하여
기본네임스페이스에서 웹 서비스를 시작합니다.$ oc run web --namespace=default --image=quay.io/openshifttest/nginx --labels="app=web" --expose --port=80다음 명령을 실행하여
prod네임스페이스를 생성합니다.$ oc create namespace prod다음 명령을 실행하여
prod네임스페이스에 레이블을 지정합니다.$ oc label namespace/prod purpose=production다음 명령을 실행하여
prod네임스페이스에alpine이미지를 배포하고 쉘을 시작합니다.$ oc run test-6459 --namespace=prod --rm -i -t --image=alpine -- sh- 다른 터미널 세션을 엽니다.
이 새 터미널 세션에서
ovn-trace를 실행하여 네임스페이스prod에서 실행되는 소스 Podtest-6459와default네임스페이스에서 실행되는 대상 Pod 간의 통신 실패를 확인합니다.$ ./ovnkube-trace \ -src-namespace prod \ -src test-6459 \ -dst-namespace default \ -dst web \ -tcp -dst-port 80 \ -loglevel 0출력 예
ovn-trace source pod to destination pod indicates failure from test-6459 to web다음 명령을 실행하여 실패 이유를 노출하려면 로그 수준을 2로 늘립니다.
$ ./ovnkube-trace \ -src-namespace prod \ -src test-6459 \ -dst-namespace default \ -dst web \ -tcp -dst-port 80 \ -loglevel 2출력 예
... ------------------------------------------------ 3. ls_out_acl_hint (northd.c:7454): !ct.new && ct.est && !ct.rpl && ct_mark.blocked == 0, priority 4, uuid 12efc456 reg0[8] = 1; reg0[10] = 1; next; 5. ls_out_acl_action (northd.c:7835): reg8[30..31] == 0, priority 500, uuid 69372c5d reg8[30..31] = 1; next(4); 5. ls_out_acl_action (northd.c:7835): reg8[30..31] == 1, priority 500, uuid 2fa0af89 reg8[30..31] = 2; next(4); 4. ls_out_acl_eval (northd.c:7691): reg8[30..31] == 2 && reg0[10] == 1 && (outport == @a16982411286042166782_ingressDefaultDeny), priority 2000, uuid 447d0dab reg8[17] = 1; ct_commit { ct_mark.blocked = 1; };1 next; ...- 1
- 기본 거부 정책이 적용되어 수신 트래픽이 차단됩니다.
purpose=production레이블이 있는 특정 네임스페이스의 모든 Pod의 트래픽을 허용하는 정책을 생성합니다. YAML을web-allow-prod.yaml파일에 저장합니다.kind: NetworkPolicy apiVersion: networking.k8s.io/v1 metadata: name: web-allow-prod namespace: default spec: podSelector: matchLabels: app: web policyTypes: - Ingress ingress: - from: - namespaceSelector: matchLabels: purpose: production다음 명령을 입력하여 정책을 적용합니다.
$ oc apply -f web-allow-prod.yamlovnkube-trace를 실행하여 다음 명령을 입력하여 트래픽이 지금 허용되는지 확인합니다.$ ./ovnkube-trace \ -src-namespace prod \ -src test-6459 \ -dst-namespace default \ -dst web \ -tcp -dst-port 80 \ -loglevel 0예상 출력
ovn-trace source pod to destination pod indicates success from test-6459 to web ovn-trace destination pod to source pod indicates success from web to test-6459 ovs-appctl ofproto/trace source pod to destination pod indicates success from test-6459 to web ovs-appctl ofproto/trace destination pod to source pod indicates success from web to test-6459 ovn-detrace source pod to destination pod indicates success from test-6459 to web ovn-detrace destination pod to source pod indicates success from web to test-64596단계에서 열린 쉘에서 다음 명령을 실행하여 nginx를 web-server에 연결합니다.
wget -qO- --timeout=2 http://web.default예상 출력
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>