Using nginx Ingress paths to redirect to multiple services

5/26/2020

I have an Azure k8s cluster, in which I want to serve two services, Jenkins and my own node app. I have the docker images and they work properly. I need to access to mydomain.com/jenkins and see my Jenkins instance. The same applies to mydomain.com/node and my node app.

The first problem I faced is that I could see the html page, but for example the css tried to load in mydomain.com/css/style.css, not mydomain.com/node/css/style.css. I fixed it with my current ingress config:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
    annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /$2
    name: ingress
spec:
  rules:
  - host: domain.com
    http:
      paths:
      - path: /(jenkins)?/?(.*)
        backend:
            serviceName: jenkins-service
            servicePort: 8080

This has been my closest attempt. With this config, I can succesfully access to Jenkins. But, if I add another path for my node app, even when I access mydomain.com/node it will redirect me to Jenkins. I know it would be a lot easier to do this with subdomains, but I have especifically been told to do it this way. I have been stuck with this all day, so I'd appreciate any help.

-- xac0
kubernetes
nginx-ingress
path

0 Answers