Accessing a remote kubernetes cluster with grafana

10/16/2018

I have a Grafana running on an EC2 instance. I installed my Kubernetes cluster k8s.mydomain.com on AWS using kops. I wanted to monitor this cluster with Grafana. Entering the below URL for Prometheus data source and the admin username and password from kops get secrets kube --type secret -oplaintext in grafana returned an error.

https://api.k8s.afaquesiddiqui.com/api/v1/namespaces/monitoring/services/prometheus-k8s:9090/proxy/graph#!/role?namespace=default

I also tried the kops add-on for prometheus but I wasn't able to access grafana using the following URL:

https://api.k8s.mydomain.com/api/v1/namespaces/monitoring/services/grafana:3000/proxy/#!/role?namespace=default

Am I doing something wrong? Is there a better way to do this?

-- Afaque Hussain
amazon-route53
amazon-web-services
grafana
kops
kubernetes

1 Answer

10/17/2018

The URLs that you specified are proxy endpoints so they are accessed through a proxy that is usually set up on your client with:

kubectl proxy

I supposed you could access it from the outside if you expose your kube-apiserver to the outside which highly unrecommended.

If you want to access the endpoint from the outside you usually do it through the Kubernetes Service which in your first case is prometheus-k8s on port 9090 and in the second case is grafana on port 3000. You didn't provide whether the services are exposed through a NodePort or LoadBalancer so the endpoint will vary depending on how it's exposed. You can find out with:

kubectl get svc
-- Rico
Source: StackOverflow