Search code examples
oracle-databasekubernetesservicestaticstatic-ip-address

How to setup static LoadBalancer IP for a service in OCI kubernetes cluster?


I have a 3-node OKE cluster setup in Oracle cloud.

I deployed an nginx ingress controller in the cluster. I'm mapping the FQDN test.myapp.com to the EXTERNAL_IP of that nginx ingress controller service.

Whenever I re-install the ingress controller during the time of testing, it gets different EXTERNAL_IP and I have to map the FQDN again to that new IP.

So it will be better if I can specify a static loadBalancer IP during the time of nginx ingress controller installation. Like this:

nginx-ingress:
  controller:
    service:
      loadBalancerIP: "125.23.119.23"

How can I achieve this in Oracle cloud (with OKE)?


Solution

  • Oracle cloud Infrastructure(OCI) supports creating LoadBalancer services in kubernetes clusters, and allows setting the LoadBalancerIP parameter too.

    But first, you have to create a Reserved Public IP address in OCI, and then specify that IP address as LoadBalancerIP of your service.

    You can do it as :

    • Go to OCI console :
      Networking -> IP management -> Reserved Public IPs.
      Click on Reserve Public IP Address
      Provide a name, and select source Oracle if that is the only public IP pool you have (default).
      Click on the Reserve button to get a reserved public IP address.

    • In OCI console, look at :
      Networking -> IP management -> Reserved Public IPs
      ( You can see a Reserved Public IP there, but not attached to any VNIC)
      Networking -> Load Balancers
      ( No Loadbalancers are listed with the IP address that we reserved )

    • Create a LoadBalancer type service in kubernetes cluster using kubectl with LoadbalancerIP provided with value of our Reserved IP Address.

    • Check kubectl get svc, and you can see that the Reserved Public IP address is assigned to the service.

    • In OCI console, look at :
      Networking -> IP management -> Reserved Public IPs
      ( You can see a public IP address reserved, attached to a VNIC for an LB)
      Networking -> Load Balancers
      ( A layer-4 Loadbalancer is added automatically with the IP address that we reserved )

    That means, when you create a Reserved Public IP, you are just reserving it for future use. A layer-4 load balancer is created and associated with that IP address only when a LoadBalancer type service is created with this Reserved IP address.

    If you delete that LoadBalancer type service, the layer-4 loadbalancer also gets deleted. But the Reserved public IP still remains there. You can assign that IP address to another service next time.

    These documentations have explanations regarding this topic :