Exercise 9.2: Configuring a NodePort

  1. CP 노드에 연결된 터미널로 이동

  2. 이전 실습에서 생성한 Service를 NodePort 형식으로 변경

    kubectl -n accounting patch svc nginx-one --type=json -p='[
    {"op": "replace", "path": "/spec/type", "value": "NodePort"}]'
  3. Service 상세 내용 확인

    kubectl -n accounting describe svc nginx-one
  4. CURL 명령어를 통해서 Service에 접근

    curl localhost:NODE_PORT

    OR

    curl localhost:$(kubectl get svc nginx-one -o=jsonpath='{.spec.ports[0].nodePort}' -n accounting)
  5. 웹 브라우저를 열고 아래의 주소로 접근 시도

    WORKER_IP_ADDRESS:NODE_PORT
  6. Iptable의 모든 규칙 확인

    sudo iptables-save
  7. KUBE-SERVICES 규칙 확인

    sudo iptables -t nat -L KUBE-SERVICES -n  | column -t
  8. KUBE-NODEPORTS 규칙 확인

    sudo iptables -t nat -L KUBE-NODEPORTS -n  | column -t
  9. 생성된 Service의 NodePort로 연결된 규칙 값을 환경변수로 저장

    {
        export NODEPORT_CHAIN=$(sudo iptables -t nat -L KUBE-NODEPORTS -n  | column -t | grep "accounting/nginx-one" | grep -oE "^KUBE-EXT-[A-Z0-9]+")
        echo $NODEPORT_CHAIN
    }
  10. NodePort로 연결된 규칙의 상세내용 확인

    sudo iptables -t nat -L $NODEPORT_CHAIN -n  | column -t
  11. NodePort로 연결된 KUBE-SERVICES 규칙 값을 환경변수로 저장

    {
        export NODEPORT_TARGET=$(sudo iptables -t nat -L $NODEPORT_CHAIN -n  | column -t | grep -oE "^KUBE-SVC-[A-Z0-9]+")
        echo $NODEPORT_TARGET
    }
  12. NodePort로 연결된 KUBE-SERVICES 규칙의 상세내용 확인

    sudo iptables -t nat -L $NODEPORT_TARGET -n  | column -t
  13. Service의 Cluster IP 확인

    kubectl -n accounting get svc nginx-one
  14. 위의 명령어로 나온 결과중의 한개의 Chain 규칙 확인

    sudo iptables -t nat -L \
    $(sudo iptables -t nat -L $NODEPORT_TARGET -n  | column -t | grep -oE "^KUBE-SEP-[A-Z0-9]+" | head -1) \
    -n  | column -t
  15. 생성된 Pod의 IP주소 확인

    kubectl -n accounting get pod -o wide

Last updated