Kubectl Port Forwarding: Have It Set Up In A Few Simple Steps
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.
Things You’ll Need Beforehand
In order to successfully port forward Kubectl, you need the following beforehand:
- Kubernetes cluster
- The Kubectl command-line tool
- Install Redis-cli software
To start with, you will need to install Redis by following these steps:
- Create a deployment that runs Redis. The deployment helps in defining the pod to be used. The output of a successful command will verify the creation of a deployment. View the pod status to check whether it is ready.
- Check the deployment created on output displays.
The deployment manages the ReplicaSet automatically. To view the status of the ReplicaSet, use: kubectl get ReplicaSet. The output will also display the ReplicaSet.
- Create a Service to expose Redis on the network and check the output for the display of the service created.
- Verify that the Redis server is running in the pod and listen on the port. The output will display the TCP port allocated to the Redis on the internet.
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’’.