Kubectl port forwarding

Kubectl is the primary command-line tool that manages the Kubernetes clusters. It is useful in administering cluster resources, deploying apps, and building complex frameworks. The port forwarding process for Kubectl requires direct and recurrent input from the user. This is because once the pod instance fails, the connection terminates, requiring the establishment of a new forward by manually entering the same command. We give you a step by step guide on how to set up Kubectl port forwarding.

How To Port Forward Kubectl

While port forwarding may be an intensive process, it may be the only way to access internal clusters; hence, a necessary process. To port forward Kubectl, you will use several Kubernetes command line on your machine and proceed as follows:

  • Use a resource name to select a matching port to forward the port. If the name of the pod is redis-master 766d459796 and the port number is 6379, your command will be:

“kubectl port-forward pods/redis-master-766d459796-258hz 7000:6379”In the above case, the Kubernetes API listens on local port 7000 and forwards data to port 6370 on the defined pod.

  • Start the Redis command line interface redis-cli –p 7000
  • Enter the ‘’ping’’ command at the Redis command line prompt. A successful ping request will return ‘’PONG’’

Leave a comment

Design a site like this with WordPress.com
Get started