Ali Khalili
Ali Khalili

Reputation: 1674

Regex string not start with sub-string for Kubernetes Ingress

I want to use regex for path of Ingress in Kubernetes to match strings starting with /app but not starting with /app/api.

My application in fact is in /app prefix and the back end part has prefix /app/api and now I want to match all requests related to my application but do not belong to back end (which should go to front end part). For this, I know that the PCRE regex is /app(/|$)(?!api)(.*). But in the documentations of Ingress Kubernetes, it is mentioned that it supports RE2 Syntax which seems that doesn't support negative look-ahead (and many other features). How else I can specify this regex? or what other options do I have?

Upvotes: 0

Views: 907

Answers (1)

derkoe
derkoe

Reputation: 6281

Just define both ingress objects - the one for the backend and the one for the frontend (you can even use prefix notation here). The path priority rules will order these entries accordingly.

Something like this should work:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress-1
spec:
  rules:
  - host: test.com
    http:
      paths:
      - path: /app/api
        backend:
          serviceName: backend-service
          servicePort: 80
      - path: /app
        backend:
          serviceName: frontend-service
          servicePort: 80

Upvotes: 2

Related Questions