How come GKE gives me different IPs for each ingress that I create?

5/11/2018

I am using multiple ingresses resource on my GKE, say I have 2 ingress in different namespaces. I create the ingress resource as shown in the yaml below. With the annotations used in the below yaml, I clearly mention that I am using the GCE controller that comes with GKE(https://github.com/kubernetes/ingress-gce). But every time I create an ingress I get different IPs, For instance sometimes I get 133.133.133.133 and for the other times I get 133.133.133.134. And it alternates between only these two IPs (it's probably between only two IPs because of quotas limit). This is a problem when I just want to reserve one IP and load balance/terminate multiple apps on this IP only.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: gce
  name: http-ingress
spec:
  backend:
    serviceName: http-svc
    servicePort: 80
-- Suhas Chikkanna
google-kubernetes-engine
kubernetes
kubernetes-ingress
load-balancing

1 Answer

5/11/2018

In your Ingress resource you can specify you need the Load Balancer to use a specific IP address with the kubernetes.io/ingress.global-static-ip-name annotation like so:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: gce
    kubernetes.io/ingress.global-static-ip-name: static-ip-name
  name: http-ingress
spec:
  backend:
    serviceName: http-svc
    servicePort: 80

You will need to create a global static IP first using the gcloud tool. See step 2(b) here: https://cloud.google.com/kubernetes-engine/docs/tutorials/configuring-domain-name-static-ip.

-- Carlos Gomez
Source: StackOverflow