LoadBalancer Service

This service is useful when there are multiple pods of same application running and the load has to be distributed among all the pods. It provides a single endpoint to access the pods and forwarding of the request to available pod gets taken care of by this service.

Loadbalancer service can be used only when the cluster where kubernetes is setup, support it natively. Otherwise, it acts same as NodePort service.

Resource yaml file for loadbalancer service is shown below.

apiVersion: v1
kind: Service
metadata:
  name: nginx-loadbalancer-service
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30008
  selector:
    type: router