17

I have been using the Google Cloud Load Balancer ingress. However, I'm trying to install a nginxinc/kubernetes-ingress controller in a node with a Static IP address in GKE.

  1. Can I use Google's Cloud Load Balancer ingress controller in the same cluster?
  2. How can we use the nginxinc/kubernetes-ingress with a static IP?

Thanks

Ray Foss
  • 3,649
  • 3
  • 30
  • 31
John
  • 171
  • 1
  • 1
  • 4

5 Answers5

13

In case you're using helm to deploy nginx-ingress.

First create a static IP address. In google the Network Loadbalancers (NLBs) only support regional static IPs:

gcloud compute addresses create my-static-ip-address --region us-east4

Then install nginx-helm with the ip address as a loadBalancerIP parameter

helm install --name nginx-ingress stable/nginx-ingress --namespace my-namespace --set controller.service.loadBalancerIP=35.186.172.1
Bernie Lenz
  • 1,967
  • 23
  • 45
  • 1
    Nice! This approach works if you need protect your nginx also: add `address_type = "INTERNAL"` and you're golden – orkenstein Sep 26 '19 at 11:19
  • 2
    How does this comapre with the kubernetes official git example in which you pass `--publish-service=$(POD_NAMESPACE)/my-static-ip` as an arg on your ingress-controller.yml? https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/static-ip – AlxVallejo Feb 05 '20 at 20:18
  • That's a good question @AlxVallejo. Your link mentions that using "loadBalancerIP" promotes an ephemeral IP to a static IP ("Now even if the Service is deleted, the IP will persist, so you can recreate the Service with spec.loadBalancerIP set to 104.154.109.191"). – Bernie Lenz Feb 10 '20 at 19:45
  • 1
    With helm 3, run follow commands: ```helm repo add stable https://kubernetes-charts.storage.googleapis.com/``` ```helm install --name nginx-ingress stable/nginx-ingress --namespace leep --set controller.service.loadBalancerIP={static-id}``` – duyetpt Jul 30 '20 at 09:39
5

First question

As Radek 'Goblin' Pieczonka already pointed you out it is possible to do so. I just wanted to link you to the official documentation regarding this matter:

If you have multiple Ingress controllers in a single cluster, you can pick one by specifying the ingress.class annotation, eg creating an Ingress with an annotation like

metadata:
  name: foo
  annotations:
    kubernetes.io/ingress.class: "gce"

will target the GCE controller, forcing the nginx controller to ignore it, while an annotation like

metadata:
  name: foo
  annotations:
    kubernetes.io/ingress.class: "nginx"

Second question

Since you are making use of the Google Cloud Platform I can give you further details regarding this implementation of Kubernetes in Google.

Consider that:

By default, Kubernetes Engine allocates ephemeral external IP addresses for HTTP applications exposed through an Ingress.

However of course you can use static IP addressed for your ingress resource, there is an official step to step guide showing you how to create a HTTP Load Balancing with Ingress making use of a ingress resource and to link to it a static IP or how to promote an "ephemeral" already in use IP to be static.

Try to go through it and if you face some issue update the question and ask!

mkobit
  • 43,979
  • 12
  • 156
  • 150
GalloCedrone
  • 4,869
  • 3
  • 25
  • 41
  • 1
    Awesome, thanks for detailed pointers. I think I got the first one and my main concern currently is second question. I tried using https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer#step_5_optional_configuring_a_static_ip_address and it works with GKE ingress but when I tried with nginx it gets an ephemeral IP address. It would be great if you can point any static-ip references for `nginx-ingress` Thank you. – John Feb 14 '18 at 09:16
  • Have you tried as well to follow Option 1 of step 5? I didn't test it, but it should work since it is present as well in this guide https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/static-ip – GalloCedrone Feb 14 '18 at 10:39
  • @GalloCedrone Option 1 of step 5 is not very useful because it is not declarative. there should be *some* way to set-it-and-forget-it. – Randy L Apr 10 '18 at 16:32
  • the second part is not what is asked for, the question is regarding a static IP for nginx-ingress, not gce ingress. – Vincent Gerris Dec 16 '20 at 14:54
4

For the nginx-ingress controller you have to set the external IP on the service:

spec:
  loadBalancerIP: "42.42.42.42"
  externalTrafficPolicy: "Local"
unguiculus
  • 413
  • 3
  • 8
  • I haven't checked with for `nginx-ingress` and this is what I was looking for. Let me check if it does work. Thank you so much for quick response. It would be great if you can point some references on this. – John Feb 14 '18 at 09:19
  • Here's some pointers: https://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/static-ip/static-ip-svc.yaml https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#servicespec-v1-core – unguiculus Feb 14 '18 at 12:54
  • What's the reason for "Local" setting? – Gajus Nov 04 '20 at 02:38
0

It is perfectly fine to run multiple ingress controllers inside kubernetes, but they need to be aware which Ingress objects they are supposed to instantiate. That is done with a special annotation like :

kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "nginx"

which tells that this ingress is expected to be provided by and only by nginx ingress controller.

As for IP, Some cloud providers allow the loadBalancerIP to be specified. with this you can controll the public IP of a service.

mkobit
  • 43,979
  • 12
  • 156
  • 150
Radek 'Goblin' Pieczonka
  • 21,554
  • 7
  • 52
  • 48
  • 1
    Thanks for the pointers. I think I have been already using this with annotations. It would be great if you can point any resources about `nginx-ingress` defining static-ip. – John Feb 14 '18 at 09:05
  • 1
    it is not nginx-ingress that defines the IP, this support is completely out of it's scope, this is done via kubernetes Service and supporting cloudprovider managing LB provisioning – Radek 'Goblin' Pieczonka Feb 14 '18 at 11:08
  • @Radek'Goblin'Pieczonka: would you provide some links to go through, i am trying to find a ways to assign the static IP for the loadbalancer when i create ingress via yaml file .. – Santhosha Jul 20 '20 at 21:30
  • @John: have you figured out the solution for this issue? if yes, would you let me know ,i am trying to achieve the same in my use case as well – Santhosha Jul 20 '20 at 21:31
-2

ONLY WORKS WITH GCE NOT INGRESS-NGINX

Create a Static Ip

 gcloud compute addresses create my-ip --global

Describe the Static Ip (this will helo you to know static IP )

gcloud compute addresses describe  ssl-ip --global

Now add these annotations:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: "gce" # <----
    kubernetes.io/ingress.global-static-ip-name: my-ip # <----

Apply the ingress

kubectl apply -f infress.yaml

(Now wait for 2 minutes) Run this to it will reflect the new ip

kubectl get ingress
Chetan Jain
  • 236
  • 6
  • 16