Search code examples
kubernetesgrafanakubernetes-ingress

How to reverse proxy grafana on ingress without using helm?


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

Solution

  • 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.