Ingress - How to dispath with base URLs?

2/3/2021

I have two services with the names svc1 and svc2. Can I make ingress dispatch the same domain with different base URLs to each service, i.e.:

ingress.domain/svc1/path-here -> svc1 gets this request, with path rewritten as /path-here

ingress.domain/svc2/path-here -> svc2 gets this request, with path rewritten as /path-here

So I can use one domain for all services on this k8s instance?

-- Romulus Urakagi Ts'ai
kubernetes
kubernetes-ingress

1 Answer

2/3/2021

you can do something like

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: public-dev
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: 50m
    nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: public-ingress
spec:
  rules:
  - host: developer.example.com
    http:
      paths:
      - backend:
          serviceName: test-service
          servicePort: 80
        path: /test-service(/|$)(.*)
      - backend:
          serviceName: test-service-2
          servicePort: 80
        path: /test-service-2(/|$)(.*)
  tls:
  - hosts:
    - developer.example.com
    secretName: public-dev
-- Harsh Manvar
Source: StackOverflow