PROBLEM: Cannot access pods in my k8s deployment for testing
SOLUTION: Use very simple port-forward method
Find your destination
Decide what do you want to access. Port forward works on services
, pods
, deployments
or even replicaSets
.
The syntax is very simple.
kubctl port-forward pod-name local-port:destination-port
Which leads to example like this:
kubectl port-forward my-pod-name 1000:3000
You can see your app through port 1000 on your local machine (working on the port 3000 on remote). Bear in mind, you are connecting directly to the service/pod/whatever, so use the port defined in the service/pod itself. Just type “localhost:1000
” in your browser/terminal.
Other examples:
You can ommit the port pair to keep just one port.
kubectl port-forward svc/some-service 3000
To match deployment
kubectl port-forward deployment/my-sweet-deployment 3000:5000
You can use the &
to set proxy on the background like this:
kubectl port-forward pods/some-pod 9000 &
Leave a Reply