Different ingress in different Namespace in kubernetes
I actually Solved my problem. I did everything correct. But only thing I did not do is to map the hostname with the same ip in Route53. And instead of accessing the website with hostname, I was accessing it from IP. Now after accessing the website from hostname, I was able to access it :)
Seems like you posted here and got your answer. The solution is to deploy a different Ingress for each namespace. However, deploying 2 Ingresses complicates matters because one instance has to run on a non-standard port (eg. 8080, 8443).
I think this is better solved using DNS. Create the CNAME records cafe-qa.example.com
and cafe-dev.example.com
both pointing to cafe.example.com
. Update each Ingress manifest accordingly. Using DNS is somewhat the standard way to separate the Dev/QA/Prod environments.
Had the same issue, found a way to resolve it:
you just need to add the "--watch-namespace" argument to the ingress controller that sits under the ingress service that you've linked to your ingress resource. Then it will be bound only to the services within the same namespace as the ingress service and its pods belong to.
apiVersion: extensions/v1beta1kind: Deploymentmetadata:namespace: my-namespacename: nginx-ingress-controllerspec: replicas: 1selector: matchLabels: name: nginx-ingress-lbtemplate: metadata: labels: name: nginx-ingress-lb spec: serviceAccountName: ingress-account containers: - args: - /nginx-ingress-controller - "--default-backend-service=$(POD_NAMESPACE)/default-http-backend" - "--default-ssl-certificate=$(POD_NAMESPACE)/secret-tls" - "--watch-namespace=$(POD_NAMESPACE)" env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace name: nginx-ingress-controller image: "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.24.1" livenessProbe: httpGet: path: /healthz port: 10254 scheme: HTTP ports: - containerPort: 80 name: http protocol: TCP - containerPort: 443 name: https protocol: TCP---apiVersion: v1kind: Servicemetadata:namespace: my-namespacename: nginx-ingressspec: type: LoadBalancer ports: - name: https port: 443 targetPort: https selector: name: nginx-ingress-lb