Skip to content

Instantly share code, notes, and snippets.

@hamidrhashmi
Last active May 23, 2025 12:55
Show Gist options
  • Save hamidrhashmi/e5116a3568026fcfc04cc4da84160416 to your computer and use it in GitHub Desktop.
Save hamidrhashmi/e5116a3568026fcfc04cc4da84160416 to your computer and use it in GitHub Desktop.
How to deploy Grafana with Promethius datasource

Pre-Requisite

  1. kubernetes cluster is ready
kubectl get nodes -o wide

OUTPUT

NAME        STATUS   ROLES           AGE     VERSION    INTERNAL-IP    EXTERNAL-IP   OS-IMAGE                         KERNEL-VERSION         CONTAINER-RUNTIME
kubmaster   Ready    control-plane   5h26m   v1.28.15   192.168.10.6   <none>        Debian GNU/Linux 12 (bookworm)   6.1.0-32-cloud-amd64   containerd://1.7.27
kubnode1    Ready    <none>          5h3m    v1.28.15   192.168.10.5   <none>        Debian GNU/Linux 12 (bookworm)   6.1.0-35-cloud-amd64   containerd://1.7.27
kubnode2    Ready    <none>          5h2m    v1.28.15   192.168.10.7   <none>        Debian GNU/Linux 12 (bookworm)   6.1.0-35-cloud-amd64   containerd://1.7.27

Install helm

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

Add helm repo for Grafana/Promethius

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

Deploye Grafana/Promethius

helm upgrade --install prometheus prometheus-community/kube-prometheus-stack \
  --namespace monitoring \
  --create-namespace \
  --set prometheus.prometheusSpec.maximumStartupDurationSeconds=60 \
  --set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false \
  --set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false

kube-prometheus-stack has been installed. Check its status by running:

kubectl --namespace monitoring get pods -l "release=prometheus"

Get Grafana 'admin' user password by running:

kubectl --namespace monitoring get secrets prometheus-grafana -o jsonpath="{.data.admin-password}" | base64 -d ; echo

Access Grafana local instance:

export POD_NAME=$(kubectl --namespace monitoring get pod -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=prometheus" -oname)
kubectl --namespace monitoring port-forward $POD_NAME 3000

uninstall

helm uninstall prometheus -n monitoring

cleanup esisting resource

kubectl delete crd alertmanagerconfigs.monitoring.coreos.com
kubectl delete crd alertmanagers.monitoring.coreos.com
kubectl delete crd podmonitors.monitoring.coreos.com
kubectl delete crd probes.monitoring.coreos.com
kubectl delete crd prometheuses.monitoring.coreos.com
kubectl delete crd prometheusrules.monitoring.coreos.com
kubectl delete crd servicemonitors.monitoring.coreos.com
kubectl delete crd thanosrulers.monitoring.coreos.com

Delete namespace

kubectl delete ns monitoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment