Last active
February 25, 2019 13:43
-
-
Save beli-sk/ae0f05e5f1a62c163f6b0d393b4958f6 to your computer and use it in GitHub Desktop.
Kubernetes: kubectl temporary environment per session
This file contains 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 | |
# to be sourced by interactive shell or added to .bashrc | |
# | |
# kubectl temporary environment per session | |
# - any `kubectl config` changes (like use-context) go to temporary file | |
# | |
KUBETMPDIR=`mktemp -d` | |
[[ "$1" == "--merged" || "$1" == "-m" ]] && touch "${KUBETMPDIR}/kubeconfig" || cp "${HOME}/.kube/config" "${KUBETMPDIR}/kubeconfig" | |
eval "function kubetmp_cleanup { | |
rm -f ${KUBETMPDIR}/kubeconfig | |
rmdir ${KUBETMPDIR} | |
}" | |
export KUBECONFIG="${KUBETMPDIR}/kubeconfig:${HOME}/.kube/config" | |
unset KUBETMPDIR | |
trap kubetmp_cleanup EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment