How to add a static IP to nginx-ingress installed via helm

3/29/2019

I would like to create an nginx-ingress that I can link to a reserved IP address. The main reason being, that I want to minimize manual steps. Currently, the infrastructure is automatically set-up with Terraform, but I cannot get nginx-ingress to use the reserved IP with it. I already have nginx-ingress working, but it creates its own IP address.

According to the nginx-ingress site (https://kubernetes.github.io/ingress-nginx/examples/static-ip/), this should be possible. First, one should create a load-balancer service:

apiVersion: v1
kind: Service
metadata:
  name: nginx-ingress-lb
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  externalTrafficPolicy: Local
  type: LoadBalancer
  loadBalancerIP: 34.123.12.123
  ports:
  - port: 80
    name: http
    targetPort: 80
  - port: 443
    name: https
    targetPort: 443
  selector:
    # Selects nginx-ingress-controller pods
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx

However, then one can update the IP via nginx-ingress-controller.yaml file with the --publish-service flag. However, I install this via helm:

helm install stable/nginx-ingress --name my-nginx --set rbac.create=true

How can I link the publish service to nginx-ingress-lb in my helm installation (or upgrade).

-- Mike
kubernetes
kubernetes-helm
nginx-ingress

1 Answer

3/29/2019

Assuming your cloud provider supports LBs with static IPs (AWS, for example, will give you a CNAME instead of an IP):

You will have to set it as a tag as the following. Once you do this, you can set your ingress annotation: kubernetes.io/ingress.class: nginx and your ingress will automatically get the same IP address.

helm install stable/nginx-ingress  --set controller.service.loadBalancerIP=XXXX,rbac.create=true
-- cookiedough
Source: StackOverflow