Exercise 9.2: Configuring a NodePort
CP 노드에 연결된 터미널로 이동
이전 실습에서 생성한 Service를 NodePort 형식으로 변경
kubectl -n accounting patch svc nginx-one --type=json -p='[ {"op": "replace", "path": "/spec/type", "value": "NodePort"}]'
Service 상세 내용 확인
kubectl -n accounting describe svc nginx-one
CURL 명령어를 통해서 Service에 접근
curl localhost:NODE_PORT
OR
curl localhost:$(kubectl get svc nginx-one -o=jsonpath='{.spec.ports[0].nodePort}' -n accounting)
웹 브라우저를 열고 아래의 주소로 접근 시도
WORKER_IP_ADDRESS:NODE_PORT
Iptable의 모든 규칙 확인
sudo iptables-save
KUBE-SERVICES 규칙 확인
sudo iptables -t nat -L KUBE-SERVICES -n | column -t
KUBE-NODEPORTS 규칙 확인
sudo iptables -t nat -L KUBE-NODEPORTS -n | column -t
생성된 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 }
NodePort로 연결된 규칙의 상세내용 확인
sudo iptables -t nat -L $NODEPORT_CHAIN -n | column -t
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 }
NodePort로 연결된 KUBE-SERVICES 규칙의 상세내용 확인
sudo iptables -t nat -L $NODEPORT_TARGET -n | column -t
Service의 Cluster IP 확인
kubectl -n accounting get svc nginx-one
위의 명령어로 나온 결과중의 한개의 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
생성된 Pod의 IP주소 확인
kubectl -n accounting get pod -o wide
Last updated