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
- 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
- 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.
- We have already created a POD named hello-pod for this demo.
- Also, we used the below manifest file to create our demo hello-pod.
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
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
Note: By default, the public Ngnix container listens to port 80.
- Service created successfully.
- Describe the service using the below command.
kubectl describe service hello-svc
- 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.
- Open the web browser from the local machine and access type the kubernetes node IP along with the Node port.
- 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.
- We can also able to access the application from Node 2.
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 (firstname.lastname@example.org).