×
Steps to create Port Forwarding in Kubernetes
Blog Cloud Computing Containers

Steps to create Port Forwarding in Kubernetes

Steps to create Port Forwarding in Kubernetes

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

 

REQUIREMENTS

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

 

INFRASTRUCTURE OVERVIEW

  • We have already installed and configured the 2 Node cluster in our demo environment.

 

CREATING A POD USING 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 created successfully.

Steps to create Port Forwarding in Kubernetes

  • For more information about the generator, please check this URL https://kubernetes.io/docs/reference/kubectl/conventions/#generators
  • 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 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 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

 

 

OTHER KUBERNETES COMMANDS

  • 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

 

Thanks for reading this blog. We hope it was useful for you to learn about port forwarding in the kubernetes environment.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.