Skip to content

Instantly share code, notes, and snippets.

@lukeledet
Created July 7, 2021 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeledet/b951cbf460eff2efe192142b587582dc to your computer and use it in GitHub Desktop.
Save lukeledet/b951cbf460eff2efe192142b587582dc to your computer and use it in GitHub Desktop.
deis_env_secrets.sh
#!/usr/bin/env bash
# Extract the environment variables from a deis app and convert them to a standard env file format
namespace=$1
pod=$2
kubectl get pod $pod -o json -n $namespace | jq -r '.spec.containers[].env[]? | [.name, .valueFrom.secretKeyRef.name, .valueFrom.secretKeyRef.key] | @tsv' | \
grep -v -e "^WORKFLOW_RELEASE" -e "^PORT" -e "^SOURCE_VERSION" -e "^DEIS_APP" -e "^DATABASE_URL" | \
while IFS=$'\t' read -r var_name secret_name secret_key; do
kubectl get secret $secret_name --namespace $namespace -o json | jq -r --arg var_name "$var_name" --arg secret_key $secret_key '.data[$secret_key] | @base64d | "\($var_name)=\"\(.)\""'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment