Skip to content

Instantly share code, notes, and snippets.

@kieranajp
Last active June 10, 2020 17:25
Show Gist options
  • Save kieranajp/139713043a66af008ef777658e536226 to your computer and use it in GitHub Desktop.
Save kieranajp/139713043a66af008ef777658e536226 to your computer and use it in GitHub Desktop.
An easy way to look at multiple data items in a Kubernetes secret.
#!/usr/bin/env bash
function usage {
echo "An easy way to look at multiple data items in a Kubernetes secret."
echo " Usage: $(basename $0) <secret> <data ...>"
exit 1
}
if [[ $# -eq 0 ]] ; then
usage
fi
set -eu
name=$1
shift;
cmd="kubectl get secret $name -o custom-columns="
for arg
do
cmd+="$arg:.data.$arg,"
done
secrets=`${cmd%?}`
echo "$secrets" | awk 'FNR==2 {print}' | tr -s ' ' '\n' | xargs -I % sh -c 'echo % | base64 -d; echo'
@kieranajp
Copy link
Author

This is a quick way to grab secrets from Kubernetes, without running kubectl get secret... and base64 decoding each manually.

Usage:

$ ./gimmesecret.sh my-app-secrets DB_USERNAME DB_PASSWORD DB_HOST DB_PORT # ... and so on
my_app
eppEna2UW9g6ZeX5
10.123.0.99
5432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment