1 min read

Quickly decode Kubernetes secrets from the terminal


Decoding Kubernetes secrets the quick way

Kubernetes secrets are base64-encoded, which means reading them requires an extra step. Instead of copying values and decoding them separately, use this one-liner:

decode_secret.sh
kubectl get secret my-secret -o jsonpath='{.data.my-key}' | base64 -d

Want to decode all keys in a secret at once? Use this:

decode_all_secrets.sh
kubectl get secret my-secret -o json | jq -r '.data | to_entries[] | "\(.key): \(.value | @base64d)"'

This pipes the secret JSON through jq, iterates over all key-value pairs, and decodes each value inline.

Note: You need jq installed for the second command. Install it with brew install jq on macOS or apt install jq on Ubuntu.