Minikube setup with Grafana and nginx ingress controller fails to honor root_url

4/29/2019

I am trying to setup a dev environment using minikube (On Mac, VirtualBox) with a custom webapp and grafana. I just can not seem to make the nginx ingress controller + grafana root_url option work together. Since Grafana, nginx and minikube are such popular tools, I must be overlooking something and I am completely out of ideas/luck. I would really really appreciate if someone can help me out here. I have spent quite a bit of time on this.

The host port 32080 is n/w mapped in Virtualbox to minikube port 32080 my-ingress-demo.com is added as 127.0.0.1 in /etc/hosts on my Mac. When I go to http://my-ingress-demo.com:32080/grafana/ I keep hitting the error (browser type: Chrome) that says

If you're seeing this Grafana has failed to load its application files 
1. This could be caused by your reverse proxy settings.
2. If you host grafana under subpath make sure your grafana.ini root_url setting includes subpath
3. If you have a local dev build make sure you build frontend using: yarn start, yarn start:hot, or yarn build
4. Sometimes restarting grafana-server can help`

First I installed nginx ingress controller using helm

helm install stable/nginx-ingress --name r1 --set controller.service.nodePorts.http=32080 --set controller.service.type=NodePort --set controller.service.nodePort=8080 --namespace default


My grafana deployment is

apiVersion: apps/v1 kind: Deployment metadata: name: grafana-demo spec: replicas: 1 selector: matchLabels: podLabel: GrafanaDemoPod template: metadata: labels: podLabel: GrafanaDemoPod spec: containers: - name: grafana-demo image: "grafana/grafana:6.1.4" imagePullPolicy: Always env: - name: GF_SERVER_ROOT_URL value: "%(protocol)s://%(domain)s:/grafana" - name: GF_SERVER_DOMAIN value: "my-ingress-demo.com" ports: - name: grafana-cntrprt containerPort: 3000 protocol: TCP livenessProbe: failureThreshold: 10 httpGet: path: /api/health port: grafana-cntrprt initialDelaySeconds: 60 timeoutSeconds: 30 readinessProbe: httpGet: path: /api/health port: grafana-cntrprt


The corresponding service is defined as follows

apiVersion: v1
kind: Service
metadata:
  name: grafana-demo-svc
  labels:
    svc_category: front-end
spec:
  selector:
    podLabel: GrafanaDemoPod
  ports:
    - name: grafana-svcport
      port: 3000
      targetPort: 3000

My ingress is defined as follows

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "nginx"
  name: grafana-app-ingress
spec:
  rules:
    - host: my-ingress-demo.com
      http:
        paths:
          - path: "/grafana/"
            backend:
              serviceName: grafana-demo-svc
              servicePort: grafana-svcport

I was expecting to see the login screen but I keep getting 404s. If I try to include the common rewrite rule in ingress config, i get too many redirects error


tried with even simpler setup of using docker-compose but still hitting the same issue. I must be doing something really stupid here

version: '3.3'
services:
  grafana:
    image: "grafana/grafana"
    container_name: 'grafanaxxx'
    ports:
      - '3000:3000'
    environment:
      - GF_SERVER_ROOT_URL=%(protocol)s://%(domain)s/grafana/
-- Nifty Hoot
grafana
kubernetes
kubernetes-ingress
minikube
nginx-ingress

1 Answer

4/29/2019

Try using this (see trailing slash)

GF_SERVER_ROOT_URL=%(protocol)s://%(domain)s/grafana/

And this path in Nginx:

paths:
  - path: "/grafana"
-- Vasily Angapov
Source: StackOverflow