How can i create mutiple nginx ingress controller in kubernetes

11/10/2021

I have 2 namespaces in my kubernetes cluster, one called first-nginx and the other called second-nginx. I am using the chart ingress-nginx.. NOT the stable/nginx-ingress as that is now deprecated.

I am attemtping to install multiple nginx controllers, because i need them to be exposed by an already created static ip in GKE. I have successfully installed my first chart in the first-nginx namespace like this

helm install nginx-ingress ingress-nginx/ingress-nginx --namespace first-nginx --set ingress-class="nginx-devices --set controller.service.loadBalancerIP={first-IP-address}"

I am now attempting to do the same with in the second namespace like this

helm install nginx-ingress-2 ingress-nginx/ingress-nginx --namespace second-nginx --set ingress-class="nginx-devices --set controller.service.loadBalancerIP={second-IP-address}"

However i get an error as shown below.

Error: rendered manifests contain a resource that already exists. Unable to continue with install: IngressClass "nginx" in namespace "" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: key "meta.helm.sh/release-name" must equal "nginx-ingress-2": current value is "nginx-ingress"; annotation validation error: key "meta.helm.sh/release-namespace" must equal "second-nginx": current value is "first-nginx"

How do i solve this ? This seems to work when i use the stable/nginx-ingress chart where i can do something like this helm install nginx-ingress-devices stable/nginx-ingress --namespace second-nginx --set controller.ingressClass="nginx-devices"

How do i acheive the same thing with the ingress-nginx

-- eagercoder
google-kubernetes-engine
kubernetes
kubernetes-helm
nginx
nginx-ingress

2 Answers

11/10/2021

you should use controller.ingressClassResource.name to set different ingress class names for them

-- Reza Nasiri
Source: StackOverflow

11/11/2021

You need to define additional controller.ingressClassResource.controllerValue for the second ingress-nginx, so that when an ingress resource refer to this class, it knows which controller to engage.

helm install nginx-ingress-devices ingress-nginx/ingress-nginx  \
  --namespace second-nginx \
  --set controller.ingressClassResource.name=second-nginx \
  --set controller.ingressClassResource.controllerValue="k8s.io/second-nginx" \
  --set controller.ingressClassResource.enabled=true \
  --set controller.ingressClassByName=true
-- gohm'c
Source: StackOverflow