How to reset grafana's admin password (installed by helm)
Asked Answered
R

4

15

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

Romaic answered 21/1, 2020 at 10:7 Comment(0)
R
29

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

namespace=monitoring
kubectl exec --namespace $namespace -it $(kubectl get pods --namespace $namespace -l "app.kubernetes.io/name=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 ✔
Romaic answered 21/1, 2020 at 10:28 Comment(4)
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 newpasswordRattle
If we restart deployment data gone. How can i solve it ?Timmerman
@kndr it's a different question, you should ask it separately (after probably having a look to persistence in kubernetes volumes)Romaic
@Timmerman See my answer. Some helm charts use a secret to store the password. That is why it gets restored after restart.Rochester
S
13

Okay, try this.

kubectl get pod -n monitoring

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

grafana-cli admin reset-admin-password NEWPASSWORD

Spotweld answered 27/12, 2020 at 18:50 Comment(0)
R
2

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)'

If you are using k9s, you can select the secret and press x to base64 decode it.

Rochester answered 14/12, 2022 at 9:12 Comment(0)
D
0

I had to decode the secret and change the password from grafana dashboard kubectl get secret loki-grafana -n loki -o jsonpath="{.data.admin-password}" | base64 --decode

Desmoid answered 26/3 at 11:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.