Search code examples
nginxkuberneteskubernetes-ingressnginx-ingress

Enable rewrite for a particular host in ingress nginx configuration


I have below ingress-nginx configuration file.

It rewrites request for one.example.com. I have added another domain, but I don't want rewrite to happen for other domain.

I went through doc, but there is now rewrite example for multiple host setup.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    certmanager.k8s.io/cluster-issuer: "letsencrypt-example-prod"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
    - hosts:
        - one.example.com
        - two.example.com
      secretName: super-secret
  rules:
    - host: one.example.com
      http:
        paths:
          - path: /customer/?(.*)
            pathType: Prefix
            backend:
              service:
                name: customer-srv
                port:
                  number: 3000
      host: two.example.com
      http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: kube-prometheus-grafana
              port:
                number: 80

I could create two separate ingress files for each host.

What will happen in that case it will create two load balancers with different dns?

(cluster is hosted on aws)


Solution

  • You can create two separate ingress.

    In that case, nothing will change your ingress controller IP would be same only for DNS.

    What will happen in that case it will create two load balancers with different dns?

    No, it won't create two load balancers.