How to Decode Kubernetes Secret

Itacen Sabacok | Apr 3, 2022

We can read kubernetes secrets with few similar options like below but decode it only with base64 because kubernetes is storing secrets base64 encoded.

Use jsonpath to parse admin user’s password inside the secret

1kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo  

Use jq to parse token inside the secret

1kubectl get secret prometheus -o json | jq -r 'data.token' | base64 -d

Use template to parse jwtkey.pem inside the secret

1kubectl get secrets/db-account --template={{.data.jwtkey}} | base64 -D

INFO

on GNU/Linux, the base64 flag is -d, not -D.