Skip to content

Instantly share code, notes, and snippets.

@chrishiestand
Last active October 6, 2017 22:19
Show Gist options
  • Save chrishiestand/8cce73c04b93f59ddd17ffd063fcb2b6 to your computer and use it in GitHub Desktop.
Save chrishiestand/8cce73c04b93f59ddd17ffd063fcb2b6 to your computer and use it in GitHub Desktop.
shortcut bash script to read a remote kubernetes secret and output to terminal
#!/usr/bin/env bash
# works on OS X
# requires jq to be installed eg: `brew install jq`
# can be easily modified to run in linux or both linux and os x
set -euo pipefail
IFS=$'\n\t'
context="${1-}"
secret_name="${2-}"
key="${3-}"
if [ -z "$context" -o -z "$secret_name" -o -z "$key" ]; then
echo "usage: $0 context secret_name key"
echo "example: $0 gke_my-project_us-central1-a_production-1 env-my-application .env"
exit 99
fi
kubectl --context="${context}" get secret "${secret_name}" -o json | jq -r ".data[\"${key}\"]" | base64 -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment