How to fix ingress 404 default backend

If you are using nginx as deployment proxy in the kubernetes and facing the issue then the below configuration can resolve the redirection issue.

Either you can include the below variables in the grafan.ini file or can expose as env variables as shown below,

GF_SERVER_DOMAIN=abc.google.com
GF_SERVER_ROOT_URL=%(protocol)s://%(domain)s:/grafana

So the Grafana deployment will look like the below one.

        apiVersion: apps/v1
        kind: Deployment
        metadata:
          name: grafana
          namespace: monitoring
        spec:
          replicas: 1
          selector:
            matchLabels:
              app: grafana
            spec:
              containers:
              - name: grafana
                image: grafana/grafana:latest
                env:
                - name: GF_SERVER_DOMAIN
                  value: "abc.google.com"
                - name: GF_SERVER_ROOT_URL
                  value: "%(protocol)s://%(domain)s:/grafana"

                ports:
                - name: grafana
                  containerPort: 3000
                resources:
                  limits:
                    memory: "2Gi"
                    cpu: "1000m"
                  requests: 
                    memory: "1Gi"
                    cpu: "500m"
                volumeMounts:
                  - mountPath: /var/lib/grafana
                    name: grafana-storage-volume
                  - mountPath: /etc/grafana/provisioning/datasources
                    name: grafana-datasources
                    readOnly: false

And you have to update the nginx server location block as below,

       location /grafana {
           proxy_pass http://grafana.monitoring.svc.cluster.local:3000;
           rewrite ^/grafana/(.*) /$1 break;
           proxy_set_header Host $host;
        }

Leave a Comment