How to expose sentry on subpath in nginx ingress?

5/11/2020

I have Sentry running in my cluster and i want to expose it on subpath using nginx ingress but it seems that it only works on root path, i tried several ways but it didn't work. Is there any configuration i can perform in order to make it work on a subpath because i've seen some examples using these two variables in the sentry.conf.py file:

SENTRY_URL_PREFIX = '/sentry'
FORCE_SCRIPT_NAME = '/sentry'

But i don't know if it works

Here is the ingress resource for sentry :

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: "sentry-ingress"
  namespace: "tools"
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
  labels:
    app: sentry-ingress
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: "sentry"
              servicePort: 9000
-- touati ahmed
kubernetes
kubernetes-helm
nginx-ingress
nginx-reverse-proxy
sentry

1 Answer

5/12/2020

Your ingress does not work properly.

In nginx ingress docs you can read:

IMPORTANT NOTES: If the use-regex OR rewrite-target annotation is used on any Ingress for a given host, then the case insensitive regular expression location modifier will be enforced on ALL paths for a given host regardless of what Ingress they are defined on.

Meaning that when you use rewrite-target annotation, path field value is treated as regexp and not as a prefix. This is why path: / is matched literally and only with /.

So if you want to use rewrite-target you should do it as following:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: sentry-ingress
  namespace: tools
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  labels:
    app: sentry-ingress
spec:
  rules:
    - http:
        paths:
          - path: /sentry/(.*)
            backend:
              serviceName: sentry
              servicePort: 9000
-- acid_fuji
Source: StackOverflow