How to decode a Kubernetes Secret
- Run
kubectl get secret app-db -n shop -o yamland paste the output into the box. JSON from-o jsonworks too. - The table lists each key with its decoded value and size, plus Copy and Copy Base64 buttons.
- The output pane holds the same Secret rewritten with
stringData, values in plain text. Binary values stay indata. - Switch to Build Secret for the reverse:
KEY=valuelines in, a Secret with Base64dataout.
The input can also be a List from kubectl get secrets -o yaml, several documents separated by ---, a Helm-rendered manifest, a bare .dockerconfigjson or just one Base64 value.
Example: what kubectl gives you and what it means
apiVersion: v1
data:
DATABASE_URL: cG9zdGdyZXM6Ly9hcHA6czNjcjN0LVBhNTVAZGI6NTQzMi9zaG9w
DB_PASSWORD: czNjcjN0LVBhNTUK
DB_USER: YXBw
kind: Secret
metadata:
name: app-db
namespace: shop
type: Opaque
| Key | Decoded | Size |
|---|---|---|
DATABASE_URL | postgres://app:s3cr3t-Pa55@db:5432/shop | 39 B |
DB_PASSWORD | s3cr3t-Pa55 plus a newline | 12 B |
DB_USER | app | 3 B |
The password is 11 characters, but the value is 12 bytes. Someone created it with echo 's3cr3t-Pa55' | base64, and the trailing newline will break the database login. The Base64 without the newline would be czNjcjN0LVBhNTU=.
What the decoder recognizes
- PEM certificates and keys such as
tls.crtandtls.keyin akubernetes.io/tlsSecret are flagged. Certificates get a link to the certificate decoder for expiry and SAN checks. - JSON values are pretty-printed.
- Binary values such as a Java keystore get their file type, a hex preview and a Download button.
.dockerconfigjsonand.dockercfgvalues are split into registry, username and password, withauthdecoded. The .dockerconfigjson decoder puts these first.
kubectl one-liners
One value. Escape dots in key names inside jsonpath:
kubectl get secret app-db -o jsonpath='{.data.DB_PASSWORD}' | base64 --decode
kubectl get secret app-tls -o jsonpath='{.data.tls\.crt}' | base64 --decode
All values, with kubectl’s built-in base64decode template function or with jq:
kubectl get secret app-db -o go-template='{{range $k, $v := .data}}{{$k}}={{$v | base64decode}}{{"\n"}}{{end}}'
kubectl get secret app-db -o json | jq '.data | map_values(@base64d)'
Creating a Secret without the newline trap:
kubectl create secret generic app-db --from-literal=DB_PASSWORD='s3cr3t-Pa55' --dry-run=client -o yaml
More shell recipes are on the Bash Base64 page.
Limits and common problems
- “No Secret with data or stringData found”: the paste is probably a Deployment or a ConfigMap. ConfigMap values are plain text and need no decoding.
- Size: a Secret is limited to 1 MiB in total. Build Secret checks the limit, key names and the DNS-style name before you apply anything.
- YAML features: the reader covers what kubectl, Helm and Kustomize produce, including block scalars and multiple documents. Anchors, aliases and merge keys are not supported.
- Helm release Secrets (
sh.helm.release.v1.*) contain Base64 of gzip data inside the Base64datavalue. Decode the outer layer here, then use the gzip Base64 decoder.
FAQ
How do I decode a Kubernetes secret with kubectl?
For one key: kubectl get secret app-db -o jsonpath='{.data.DB_PASSWORD}' | base64 --decode. For all keys at once, paste the -o yaml output here, or use the go-template or jq one-liners on this page.
Are Kubernetes Secrets encrypted?
The data field is only Base64, which anyone with read access can reverse. Encryption at rest in etcd is a separate cluster setting, and RBAC decides who can read Secrets. See encoding vs encryption.
Why does my decoded secret have a newline at the end?
The value was created with echo instead of echo -n, so the newline was encoded too. Its Base64 then often ends in K, o= or Cg==. Recreate it with printf '%s' value | base64 or with kubectl create secret --from-literal.
What is the difference between data and stringData?
data holds Base64 values, stringData takes plain text that the API server encodes for you on write. Reads always return data. The output pane here rewrites the Secret with stringData so you can edit and re-apply it.