13

My password once worked, but I don't remember if I changed it or not.

However, I can't reset it.

I tried with no success:

kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo 
> DpveUuOyxNrandompasswordYuB5Fs2cEKKOmG <-- does not work (anymore?)

PS: I did not set any admin email for web-based reset

Vincent J
  • 4,968
  • 4
  • 40
  • 50

3 Answers3

21

Ok found. Best way is to run grafana-cli inside grafana's pod.

kubectl exec --namespace default -it $(kubectl get pods --namespace default -l "app=grafana,release=grafana" -o jsonpath="{.items[0].metadata.name}") grafana-cli admin reset-admin-password yourNewPasswordHere

INFO[01-21|10:24:17] Connecting to DB                         logger=sqlstore dbtype=sqlite3
INFO[01-21|10:24:17] Starting DB migration                    logger=migrator

Admin password changed successfully ✔
Vincent J
  • 4,968
  • 4
  • 40
  • 50
  • 2
    I had to change the cmd line a bit: kubectl exec --namespace prometheus -c grafana -it $(kubectl get pods --namespace prometheus -l "app.kubernetes.io/name=grafana" -o jsonpath="{.items[0].metadata.name}") -- grafana-cli admin reset-admin-password newpassword – David Tinker Jun 22 '21 at 08:31
  • If we restart deployment data gone. How can i solve it ? – Orkun Mar 31 '22 at 06:16
  • @kndr it's a different question, you should ask it separately (after probably having a look to persistence in kubernetes volumes) – Vincent J Mar 31 '22 at 07:59
  • @Orkun See my answer. Some helm charts use a secret to store the password. That is why it gets restored after restart. – Dojo Dec 14 '22 at 09:13
12

Okay, try this.

kubectl get pod -n monitoring

kubectl exec -it grafana-00000000aa-lpwkk -n monitoring -- sh

grafana-cli admin reset-admin-password NEWPASSWORD

user5866501
  • 483
  • 2
  • 5
  • 12
1

If you installed it via kube-prometheus-stack helm chart then the admin password is stored in a secret named kube-prometheus-stack-grafana. You need to set it there are restart the Grafana pod.

Alternatively, you can just decode the password and use:

kubectl get secrets/kube-prometheus-stack-grafana -o json | jq '.data | map_values(@base64d)'

Dojo
  • 5,374
  • 4
  • 49
  • 79