Steps To Create Port Forwarding In Kubernetes

Steps to create PORT forwarding

In this blog, we will show you the steps to create Port Forwarding in the Kubernetes Environment.

REQUIREMENTS

  • 2 Node Cluster ( 1 Master VM with 2 Nodes)
  • Kubernetes Components

INFRASTRUCTURE OVERVIEW

  • Firstly, we need to install and configure the 2-node cluster in our environment. We had already installed and configured the 2 Node cluster in our demo environment. To learn more check our blog post.

Creating a POD using the Kubectl command

  • Login to the kubernetes master server through Putty.
Steps to create Port Forwarding in Kubernetes
  • Use the below command to create a POD.

Syntax: kubectl run <pod name> --image=<image-name> --port=<port number of container application> --generator=run-pod/v1

Example: kubectl run web-pod --image=nginx --port=80 --generator=run-pod/v1

Steps to create Port Forwarding in Kubernetes
  • POD was created successfully.
Steps to create Port Forwarding in Kubernetes
  • For more information about the generator, click here.
  • The new POD is available on the list.
Steps to create Port Forwarding in Kubernetes
  • We can also view the detailed information about the POD using the describe command.

kubectl describe pods web-pod

Steps to create Port Forwarding in Kubernetes
Steps to create Port Forwarding in Kubernetes

Configure Port forwarding

  • Use the below command to create a Port forwarding for a container.

Syntax: kubectl port-forward <pod name> <local machine port>:<pod container port>

Example: kubectl port-forward web-pod 8888:80

Steps to create Port Forwarding in Kubernetes
  • The port forwarding is in a running state.
Steps to create Port Forwarding in Kubernetes
  • Open a duplicate session of the master server and access the container using the command.

curl 127.0.0.1:8888

Steps to create Port Forwarding in Kubernetes
  • You can able to see the Nginx homepage.
Steps to create Port Forwarding in Kubernetes
  • This is an easy method to verify the container ports without creating the services.

Kubernetes Logs

  • We can verify the POD logs using the below command.

Syntax: kubectl logs <pod name>

Example: kubectl logs web-pod

Steps to create Port Forwarding in Kubernetes
  • You can able to see the POD logs as shown below.
Steps to create Port Forwarding in Kubernetes
  • Use the below command to display the POD internal IP.

kubectl get pods -o wide

Steps to create Port Forwarding in Kubernetes
  • To display the POD configuration in YAML format.

Syntax: kubectl get pods <pod name> -o yaml

Example: kubectl get pods web-pod -o yaml

Steps to create Port Forwarding in Kubernetes
  • To display the POD configuration in JSON format.

kubectl get pods web-pod -o json

Steps to create Port Forwarding in Kubernetes

View Post>>

View Post>>