Kubernetes provides us a feature to port forward an application which is running in the internal network through the Kubernetes client host. By default it binds to the 127.0.0.1 and it won’t accept requests from external hosts.

The syntax of port forwarding command is given below.

kubectl port-forward svc/[service-name] -n [namespace] [external-port]:[internal-port]

I am giving an example of port forward command below. The below command will port forward the service running in port 443 to the port 8080 in the kubectl client host.

kubectl port-forward svc/argocd-server -n argocd 8080:443

The screenshot after executing the command is given below.

When I try to open this URL from another machine using the client machine’s IP Address and Port, it is not working. The reason is because the 8080 port is bound to 127.0.0.1.

To make it working, we have to make this port listen to 0.0.0.0.

This can be achieved easily by adding an additional parameter to the command. The syntax is given below.

kubectl port-forward svc/[service-name] -n [namespace] [external-port]:[internal-port] --address='0.0.0.0'

Now it will accept requests from all host. The sample screenshot is given below.

I hope this article is useful. Feel free to comment if you have any questions.