Steps to access the POD from outside the cluster
In this blog, we will show you the Steps to access the POD from outside the cluster in Google Kubernetes environment.
- 2 Node Cluster ( 1 Master VM with 2 Nodes)
- Kubernetes Components
- We have already installed and configured the 2 Node cluster in our demo environment.
- Please check the URL https://www.assistanz.com/steps-to-install-kubernetes-cluster-manually-using-centos-7/ for more information.
- We can able to access our application through services. Our application can be access from the inside and the outside the cluster.
- Services will be the 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 through cluster-wide. Using this port we can able to access our application from outside.
- We are creating 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 Labels 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, 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 are able to access the nginx homepage successfully. It’s a containerized web server listening in the 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.
Thanks for reading this blog. We hope it was useful for you to learn to access the POD from outside the cluster.