Steps to access the POD from outside the cluster using the Load Balancer.

In this blog, we will show you the steps to access the POD from outside the cluster using the load balancer.

Create a Kubernetes pod.

E.X: We create an Nginx pod and try to access it outside the world.
1. create a YAML file using vim <filename.yaml>
2. nginx sample yaml file.
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
name: nginx
spec:
containers:
— image: nginx
name: nginx
Nginxpod.yaml
*We tied pods with services using Labels.
3. create a pod using below comment
kubectl create -f <filename.yaml>
4. To check pod is created or not.
kubectl get pod

Create a service YAML file for Nginx using load balancer.

  1. Create a service.yaml file
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
name: nginx
spec:
type: LoadBalancer
ports:
— port: 80
name: http
selector:
name: nginx
service.yaml
2. Create a service file.
kubectl create -f <filename.yaml>
3. To check service is created or not use below cmd.
kubectl get svc
svc cmd
4. Here you got a network load balancer endpoint.

VERIFICATION:

Open the web browser from the local machine and paste the load balancer endpoint here.
We are able to access the Nginx homepage successfully
WRITTEN BY

Harshal Kathar

DevOps Engineer

Comments