본문 바로가기
ops/kubernetes

[Kubernetes] Command - "kubectl port-forward"

by seohan1010 2024. 6. 21.

 

kubernetes lab은 위와 같다. 

 

 

 

마스터 노드의 주소

 

 

 

worker-node와 잘 연결이 되어있다. 

 

 

 

 pod를 생성한다.

 

 

 

 

pod의 주소

 

 

curl 명령어를 실행하면은 

연결이 되지 않는다. 

 

마스터 노드의 주소 "10.0.1.201"과

워커 노드의 주소 "10.44.0.1"이 

다른 네트워크에 속해있기 때문이다. 

 

 

해결방법

 

 

 

 

worker-node-1 에서 실행되고 있는 test1 pod는

worker-node-1 80번 포트로 

실행이 되고 있다. 

 

 

 

 

worker-node-1의 80번 포트와 

control-plain의 80번 포트를 

"port-forwarding"해준다. 

 

 

 

정상적으로 명령어가 실행이 된다. 

 

 

port-forwarding 관련은 아래의 포스팅을 참고

 

https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/

 

Use Port Forwarding to Access Applications in a Cluster

This page shows how to use kubectl port-forward to connect to a MongoDB server running in a Kubernetes cluster. This type of connection can be useful for database debugging. Before you begin You need to have a Kubernetes cluster, and the kubectl command-li

kubernetes.io

 

 

 

포트 포워드 해제시에는 아래의 포스팅을 참고 

 

https://stackoverflow.com/questions/37288500/how-to-undo-a-kubectl-port-forward

 

how to undo a kubectl port-forward

If I forwarded a port using kubectl port-forward mypod 9000:9000 How can I undo that so that I can bind port 9000 with another program? Additionally, how can I test to see what ports are forwarded?

stackoverflow.com