Helm - Accessing Grafana over Nginx Ingress

7/31/2018

I deployed Grafana using Helm with the following content (showing only relevant parts) in configuration file:

ingress:
  enabled: true
  annotations:
    ingress.kubernetes.io/rewrite-target: /grafana
    kubernetes.io/ingress.class: nginx-internal

Then I deployed an Nginx-Ingress using Helm with following config:

controller:
  config:
    ssl-redirect: "false"
  ingressClass: nginx-internal

  service:
    type: NodePort
    nodePorts:
      http: 30080
      https: 30443

Here is the description of Ingress:

Name:             mottled-magpie-grafana
Namespace:        kube-system
Address:
Default backend:  default-http-backend:80 (<none>)
Rules:
  Host                 Path  Backends
  ----                 ----  --------
  chart-example.local
                       /   mottled-magpie-grafana:80 (10.32.0.93:3000)
Annotations:
  ingress.kubernetes.io/rewrite-target:  /grafana
  kubernetes.io/ingress.class:           nginx-internal
Events:
  Type    Reason  Age   From                      Message
  ----    ------  ----  ----                      -------
  Normal  CREATE  1h    nginx-ingress-controller  Ingress kube-system/mottled-magpie-grafana
  Normal  CREATE  1h    nginx-ingress-controller  Ingress kube-system/mottled-magpie-grafana
  Normal  CREATE  1h    nginx-ingress-controller  Ingress kube-system/mottled-magpie-grafana
  Normal  UPDATE  1h    nginx-ingress-controller  Ingress kube-system/mottled-magpie-grafana
  Normal  CREATE  53m   nginx-ingress-controller  Ingress kube-system/mottled-magpie-grafana

It all installed fine, but I am unable to access Grafana from my host when I try curl <hostIp>:30080/grafana.

However, this works:

curl <hostIp>:30080 -H "HOST: chart-example.local"

The setup is running on a local VM. How do I access Grafana from my browser (without manually adding the Host header)?

-- Jaskaranbir Singh
kubernetes
kubernetes-helm
kubernetes-ingress
nginx

1 Answer

7/31/2018

Your ingress is set up for only one host - chart-example.local, which comes from that Helm chart's Values.yaml. If you are running no other ingresses, replace chart-example.local in Values.yaml with "*", this will match any Host. If you have other ingresses, this could steal their traffic, so make it "localhost" or "127.0.0.1" and you'll be able to connect to either of those two.

What I like to do is create a fake host name, like foo.local, and add that to /etc/hosts so that it's a valid hostname.

-- Marcin Romaszewicz
Source: StackOverflow