Create an IP Address for Kubernetes Cluster Using Load Balancer

You can use the Load Balancer to provide a stable and reliable IP address for your Kubernetes cluster. It will expose your application, such as Nginx deployment, to the internet. This IP address should remain stable as long as the service exists.

Example

Define type as LoadBalancer to create a service of type Load Balancer. When this service is created, most cloud providers will automatically provision a Load Balancer with a stable external IP address. Configure the ports that the service will listen on and forward the traffic to. Define the selector field to set the Pods to which the traffic will be forwarded.

apiVersion: v1
kind: Service
metadata:
  labels:
    run: nginx
  name: nginx
spec:
  ports:
    - port: 80
      targetPort: 80
  selector:
    run: nginx
  type: LoadBalancer
  loadBalancerIP: CRIP-IP

Note:

  • Ensure that your Cloud provider supports the automatic creation of external Load Balancers for Kubernetes services.

  • You need at least two remaining free CRIPs for regular maintenance.

  • You need to replace the Nginx related labels and selectors with those relevant to your application.

Last updated