skip to Main Content

I wanna reverse proxy grafana. I am not using domain to access ingress, instead i use the node’s IP. I am using rewrite target to do the job but, it doesnt work. It is always redirect the app to /login without prefix /grafana (404 error). Expected url is /grafana/login.

apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
  labels:
    app.kubernetes.io/component: controller
  name: nginx-example-grafana
  namespace: grafana
  annotations:
    ingressclass.kubernetes.io/is-default-class: "true"
spec:
  controller: k8s.io/ingress-nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress-grafana
  namespace: grafana
  annotations:
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  ingressClassName: nginx-example-grafana
  rules:
    - http:
        paths:
          - path: /grafana(/|$)(.*)
            pathType: ImplementationSpecific
            backend:
              service:
                name: grafana
                port:
                  number: 3000

2

Answers


  1. I’m not sure I understand. It is the expected behavior with the nginx.ingress.kubernetes.io/rewrite-target: /$2 annotation. I will redirect to the second capture group of the regular expression of your path, therefore changing /grafana/login to /login since /login matches the second capture group of your regex.

    I would simply remove the redirection, and leave the path to /grafana.

    Login or Signup to reply.
  2. As per the official documentation from Grafana Labs,you can Include the sub path at the end of the root_url in the Grafana configuration file and set serve_from_sub_path to true.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search