0

I use ingress nginx (https://kubernetes.github.io/ingress-nginx/)

This is how i build my project in GKE.

Step 1: Install ingress controller (https://kubernetes.github.io/ingress-nginx/deploy/#gce-gke)

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/cloud/deploy.yaml

Step 2: I use skaffold dev to run my k8s file.

Below is my ingress-srv file

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-srv
  annotations:
    ingressClassName: nginx
    nginx-ingress.kubernets.io/user-regex: 'true'
spec:
  rules:
    - host: ''
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: nix-api-clusterip-srv
                port:
                  number: 3020

After that, I can get one external Ip address in GKE but when I delete the ingress controller and repeat step 1 (install the ingress controller again). I will get a new external Ip address.

How can I get a static Ip address even though i deleted the ingress controller?

Thank you

Alan Tang
  • 31
  • 9

1 Answers1

0

As per the official documentation, it is possible to use the same static-ip even though the Ingress controller is deleted and recreated.

Make sure your Ingress targets exactly one Ingress controller by specifying the ingress.class annotation in the yaml file.Since instances of the ingress NGINX controller actually run on nodes in a cluster, by default NGINX Ingresses will only get static IPs if the cloud provider supports static IP assignments to nodes.

To acquire a static IP for the ingress-nginx-controller, you can use the Service of Type=LoadBalancer.

Create a Load balancer Service with a name ingress-nginx-lb and wait for it to acquire an IP.

$ kubectl create -f static-ip-svc.yaml
service "ingress-nginx-lb" created

$ kubectl get svc ingress-nginx-lb 
It will show the details as below:
NAME        ingress-nginx-lb
CLUSTER-IP      10.0.138.113
EXTERNAL-IP     104.154.109.191
PORT(S)         80:31457/TCP,443:32240/TCP
AGE             15m

Once it is done, update the Ingress controller so it adopts the static IP of the Service by passing the --publish-service flag.

$ kubectl create -f ingress-nginx-controller.yaml 
deployment "ingress-nginx-controller" created

Every Ingress created with the ingress.class annotation set to nginx will get the IP which was allocated in the previous step

$ kubectl create -f ingress-nginx.yaml 
ingress "ingress-nginx" created

$ kubectl get ing ingress-nginx
It will show IP address for ingress-nginx as 104.154.109.191 (Same IP as Load balancer IP)

Additionally, You can specify a static IP address by using the annotation kubernetes.io/ingress.regional-static-ip-name on your Ingress resource as per the document.

To promote the allocated IP to static, you can update the Service manifest as follows:

$ kubectl patch svc ingress-nginx-lb -p '{"spec": {"loadBalancerIP": "104.154.109.191"}}' 
"ingress-nginx-lb" patched

Even if the Ingress is deleted and re-created, the IP will be retained by using the Load balancer. The same load balancer IP is shared amongst all Ingresses, because all requests are proxied through the same set of NGINX controllers.You can recreate the Service with spec.loadBalancerIP set to 104.154.109.191

Alternatively, you can also refer to the Google document related to Static IP reservation.

  • @Alan Tang, Let me know if the provided information was helpful.If yes,you can check this link https://stackoverflow.com/help/someone-answers.I am happy to assist you in case of any queries. – Kiran Kotturi Aug 29 '23 at 07:05