Steps To Access The POD From Outside The Cluster

In this blog, we will show you the easy steps to access the POD from outside the Kubernetes cluster.

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

Infrastructure Overview

  • Firstly we need to create and install the 2-node cluster in the environment.
  • We have already installed and configured the 2 Node cluster in our demo environment. To know how to install and configure visit the

Kubernetes service

  • We can able to access our application through services. Our application can be accessed from the inside and the outside of the cluster.
  • Services will be reliable between the POD and client end.
  • The service will get a virtual IP from the DNS and it will never change. Also, it gets a DNS name and a Port number. The port number is available cluster-wide. Using this port we can able to access our application from outside.
  • We are creating an endpoint object along with the services. It contains the POD information. The endpoint will get updated when a POD creates (or) deletes.
  • We tied pods with services using Labels.
  • We will specify the Label information in the POD creation manifest file.
  • DNS cluster add-on implements DNS service in the cluster.
  • Services get DNS names that are resolvable inside the cluster.

Environment overview

  • We have already created a POD named hello-pod for this demo.
Steps to access the POD from outside the cluster
  • Also, we used the below manifest file to create our demo hello-pod.
Steps to access the POD from outside the cluster

Note: Labels are mandatory for kubernetes services. So we need to specify the label information in the manifest file for POD creation.

  • Currently, there are 2 nodes in the cluster. Node 1 IP is 192.168.3.82 and Node 2 IP is 192.168.3.83
Steps to access the POD from outside the cluster

Creating a service

  • From the Kubernetes Master server, execute the below command to create a service.

Syntax: kubectl expose pod <pod-name> --name=<name for the service> --port=<container application port> --type=NodePort

Example: kubectl expose pod hello-pod --name=hello-svc --port=80 --type=NodePort

Steps to access the POD from outside the cluster

Note: By default, the public Ngnix container listens to port 80.

  • Service created successfully.
Steps to access the POD from outside the cluster
  • Describe the service using the below command.

kubectl describe service hello-svc

Steps to access the POD from outside the cluster
  • The service virtual IP is 10.103.224.243 and the NodePort is 30134. Using this node port we can able to access the application from your local machine.
  • Services Port will be available from 30000 to 32767.

Verification

  • Open the web browser from the local machine and access type the kubernetes node IP along with the Node port.
Steps to access the POD from outside the cluster
  • We can access the nginx homepage successfully. It’s a containerized web server listening in port 80 and we mapped it to 30134 in every node in the cluster.
Steps to access the POD from outside the cluster
  • We can also able to access the application from Node 2.
Steps to access the POD from outside the cluster

Video Tutorial

Thank you for taking the time to read our blog on “How to access the POD from outside the K8s cluster?”. We hope you found the information valuable and insightful. If you find any issues with the information provided in this blog don’t hesitate to contact us (info@assistanz.com).

View Post>>

View Post>>