Kubernetes - service type LoadBalancer to use specific ip address every time deployed in AKS

2/26/2021

In Azure, i am using helm to deploy a service (type=loadbalancer)

Below is the manifest file

apiVersion: v1
kind: Service
metadata:
  name: {{ template "app.fullname" . }}-service-lb
  labels:
    app: {{ template "app.fullname" . }}-service-lb
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
  type: LoadBalancer
  ports:
    - port: {{.Values.appServPort}}
      nodePort: {{.Values.lbPort}}
      protocol: TCP
  selector:
    app: {{ template "app.fullname" . }}-service

Is it possible to tell kubernetes cluster to use a specific ip every time as an External IP. Whenever I deploy the service?

/-- EDITED-- /

Every time the loadbalancer service is deployed, a new External ip is allocated, in my case wanted to specify to use the same ip, and assume that ip address is not used within the network.

/---- /

My understanding is the Kubernetes cluster will allocate an External Ip everytime its deployed, it not specified in the manifest file.

There is an Azure documentation which details on how to use a static Ip within the manifest file and demo link.

-- Tim
azure
kubernetes
kubernetes-service

1 Answer

2/27/2021

I'm just quoting from the docs

If you would like to use a specific IP address with the internal load balancer, add the loadBalancerIP property to the load balancer YAML manifest. In this scenario, the specified IP address must reside in the same subnet as the AKS cluster and must not already be assigned to a resource. For example, you shouldn't use an IP address in the range designated for the Kubernetes subnet.

apiVersion: v1
kind: Service
metadata:
  name: internal-app
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
  type: LoadBalancer
  loadBalancerIP: 10.240.0.25
  ports:
  - port: 80
  selector:
    app: internal-app
-- silent
Source: StackOverflow