Start Preparation Smartly

We have the collection to start prepartion smartly.

Start Assessment

Learn Kubernetes | K8s Tutorial for Beginners

  DevOps Tech Hub

116 Followers

Load Balancer service on Kubernetes


 What is Load Balancer Service?

Create Deployment manifest file

#Deployment for Load balancer service
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-app
  template:
    metadata:
      labels:
        app: nginx-app
    spec:
      containers:
      - name: nginx-container
        image: nginx
        ports:
        - containerPort: 80

Create Load Balancer Service manifest file

#Load Balancer service
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    app: nginx-app
spec:
  selector:
    app: nginx-app
  type: LoadBalancer
  ports:
  - nodePort: 31000
    port: 80
    targetPort: 80

Deploy Deployment controller

[root@ ~]$kubectl apply -f createDeployment.yaml
deployment.apps/nginx-deployment created
[root@ ~]$

Deploy Load Balancer Service 

[root@ ~]$kubectl apply -f createLoadBalancer.yaml
service/nginx-service created
[root@ ~]$

Verify Deployment

[root@ ~]$kubectl get deploy
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   0/1     1            0           119s
[root@ ~]$

Verify Replica Set

[root@ ~]$kubectl get rs
NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-7dcc9fb9c4   1         1         0       2m30s
[root@ ~]$

Verify running PODs

[root@ ~]$kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-7dcc9fb9c4-k4dxv   0/1     Pending   0          4m1s
[root@ ~]$

Verify Services 

[root~]$kubectl get svc
NAME            TYPE           CLUSTER-IP      EXTERNAL-IP                                                              PORT(S)        AGE
kubernetes      ClusterIP      172.31.10.1     <none>                                                                   443/TCP        41m
nginx-service   LoadBalancer   172.31.10.123   ad2f7508a10cf4ac0a3d8b534e395850-603244326.us-east-1.elb.amazonaws.com   80:31000/TCP   2m15s
[root@ ~]$

Verify Load Balancer created in AWS Consol.



Previous