1

I am using nginx ingress controller in my k8s cluster, with AWS L4 NLB with SSL Redirection based on this documentation: https://github.com/helm/charts/tree/master/stable/nginx-ingress#aws-l4-nlb-with-ssl-redirection

My website is multi-tenant: subdomain.domain.com. Since some limitations, we need to redirect requests from my main page subdomain.domain.com to subdomain.domain.com/app But ONLY the root url and not any other paths.

For example:

only

subdomain.domain.com goes to subdomain.domain.com/app
but

subdomain.domain.com/api/v1 stays on subdomain.domain.com/api/v1

Any way to do this using server-snippet redirect rules? or should I consider other options? like a backend service etc...

Thanks!

SimonSK
  • 153
  • 4
  • 12

2 Answers2

0

You'll want to use a Path type to match where you want to send traffic.

Also, you're pointing to a deprecated chart; the maintained and up-to-date chart is at https://github.com/kubernetes/ingress-nginx/tree/main/charts/ingress-nginx.

You can set up redirects with annotations or send / straight to what /app service

In the values.yaml controller.annotations

Or use the AWS NLB static chart that has it setup already

https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.5.1/deploy/static/provider/aws/nlb-with-tls-termination/deploy.yaml

https://kubernetes.io/docs/concepts/services-networking/ingress/#path-types

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-wildcard-host
spec:
  rules:
  - host: "subdomain.domain.com"
    http:
      paths:
      - pathType: Exact
        path: "/"
        backend:
          service:
            name: app-service
            port:
              number: 80

      - pathType: Exact
        path: "/api/v1"
        backend:
          service:
            name: apiv1-service
            port:
              number: 80
strongjz
  • 4,271
  • 1
  • 17
  • 27
0

You can use annotations app-root. Please refer this link: https://kubernetes.github.io/ingress-nginx/examples/rewrite/#app-root

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/app-root: /app
  name: ingress-app-root
spec:
  rules:
  - host: subdomain.domain.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: http-svc
            port: 
              number: 80