Last active
February 16, 2017 21:52
-
-
Save cdornsife/8160be525c1829577580582702601064 to your computer and use it in GitHub Desktop.
I use this to store cluster creation configs to the cluster itself. This prevents me from having to use S3 or GCS which means I have to write code to deal with each provider. This is provider agnostic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# tar.gz the config files. Store them as a kubernetes secret in namespace kube-system | |
set -o errexit | |
set -o pipefail | |
set -o nounset | |
KCTL="kubectl --kubeconfig=/your/kubeconfig.json --namespace=kube-system" | |
SECRET="my-fancy-configs" | |
usage() { | |
cat <<EOF >&2 | |
$0: [--upload|--download|--clean] | |
EOF | |
exit 1 | |
} | |
if [[ "$#" != 1 ]]; then | |
usage | |
fi | |
upload() { | |
echo 'packaging and uploading configs' | |
find . \( -iname ".config*" -or -iname "whatever.*" -or -regex "\./your/.*/\.tmp" \) -print0 | \ | |
xargs -0 tar -zcvf configs.tar.gz | |
${KCTL} create secret generic ${SECRET} --from-file=gz=configs.tar.gz | |
rm configs.tar.gz | |
} | |
download() { | |
echo 'downloading and unpacking configs' | |
${KCTL} get secret ${SECRET} -o json | jq -r '.data.gz' | base64 -d > configs.tar.gz | |
tar -zxvf configs.tar.gz | |
rm configs.tar.gz | |
} | |
clean() { | |
echo 'removing configs from cluster' | |
${KCTL} delete secret ${SECRET} | |
} | |
case ${1} in | |
--upload) | |
upload | |
;; | |
--download) | |
download | |
;; | |
--clean) | |
clean | |
;; | |
*) | |
usage | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment