kubernetes port forwarding - ghdrako/doc_snipets GitHub Wiki

kubectl port-forward <pod-name> 28015:27017
kubectl port-forward pods/<pod-name> 28015:27017
kubectl port-forward deployment/<deployment-name> 28015:27017
kubectl port-forward replicaset/<rs_name> 28015:27017
kubectl port-forward service/<srv_name> 28015:27017

Listen on port 8443 locally, forwarding to the targetPort of the service's port named "https" in a pod selected by the service

kubectl port-forward service/myservice 8443:https

Listen on port 8888 on all addresses, forwarding to 5000 in the pod

kubectl port-forward --address 0.0.0.0 pod/mypod 8888:5000

Listen on port 8888 on localhost and selected IP, forwarding to 5000 in the pod

kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8888:5000

Listen on a random port locally, forwarding to 5000 in the pod

kubectl port-forward pod/mypod :5000

Note: kubectl port-forward does not return. To continue with the exercises, you will need to open another terminal.

Optionally let kubectl choose the local port

kubectl port-forward deployment/mongo :27017

Note: kubectl port-forward is implemented for TCP ports only. Not support UDP port.

⚠️ **GitHub.com Fallback** ⚠️