1

I have the following ingress config:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Exact
        backend:
          serviceName: web-service
          servicePort: 5000
      paths:
      - path: /api/tasks/.*
        pathType: Prefix
        backend:
          serviceName: tasks-service
          servicePort: 5004
      paths:
      - path: /api/.*
        pathType: Prefix
        backend:
          serviceName: um-service
          servicePort: 5001

I'm intending to load the frontend by default then, use the other paths for loading other services. I would like to get the total tasks count from /api/tasks/total_count and raise new task from /api/tasks/raise. At the same time, I would like to login using /api/auth/login/ and view other users with /api/users/list both served with the um-service. The above configuration only returns the default path of the last service which is the um-service. How do I configure so that web loads by default, then either /api/auth/login or /api/users/list are routed to the um-service and /api/tasks/ is also routed to the tasks service? Kindly advice

Denn
  • 447
  • 1
  • 6
  • 27

1 Answers1

3

If I understand you correctly, you want to achieve that result:

$ curl <MY_DOMAIN>/api/auth/login
um-service
$ curl <MY_DOMAIN>/api/users/list
um-service
$ curl <MY_DOMAIN>/api/tasks/
tasks-service
$ curl <MY_DOMAIN>/
web-service

You almost did everything right, but paths should only be given once

Try this configuration:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: web-service
          servicePort: 5000
      - path: /api/tasks/.*
        backend:
          serviceName: tasks-service
          servicePort: 5004
      - path: /api/.*
        backend:
          serviceName: um-service
          servicePort: 5001
matt_j
  • 4,010
  • 1
  • 9
  • 23