Kubernetes Secrets in plain-text

I’ve seen some elaborate solutions to easily retrieve Kubernetes secrets in plain-text. This is what I came up with to make my life easier.


$ brew install jq


Create a file (e.g. ~/.shellfn) containing the following shell function:

function ksecret () {
  kubectl get secrets $@ -ojson | jq '{name: .metadata.name, data: .data | map_values(@base64d)}'

Include the file in your .zshrc, .bashrc, etc. or just via your CLI source ~/.shellfn.


$ ksecret -n my-namespace the-secret


  "name": "the-secret",
  "data": {
    "foo": "something in plain-text",
    "bar": "more something in plain-text"

Use with with pbcopy or jq for additional convenience, e.g.

$ ksecret -n my-namespace the-secret | pbcopy

Enrico Stahn © 2011 - 2021