简体   繁体   中英

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

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).

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

The original answer is a bit outdated, so here's a working example for 2022.

Note: You cannot edit an existing ingress-nginx load balancer service, but you can pass the external IP you want it to use when installing it. Keep in mind, you need to have that external IP set up ahead of time in your cloud environment.

Here is the command that worked for me when performing a helm installation:

helm upgrade --install ingress-nginx ingress-nginx \
  --repo https://kubernetes.github.io/ingress-nginx \
  --namespace ingress-nginx --create-namespace \
  --debug \
  --set controller.service.loadBalancerIP=<YOUR_STATIC_IP>

More info:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM