Last active
April 8, 2020 11:07
-
-
Save abelgvidal/2a0a9e6bdc057e293c476a4ee1307384 to your computer and use it in GitHub Desktop.
assume role for kubernetes
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
;; used as assume_aws production | |
regenerate_kubeconfig() { | |
echo "Configuring for ${1} environment\n" | |
if [ "${1}" = "production" ]; then | |
echo "Selecting production\n" | |
SRC_CLUSTER="stable-20200129" | |
else | |
echo "Selecting sandbox\n" | |
SRC_CLUSTER="unstable-20200128" | |
fi | |
echo "Updating kubeconfig for ${SRC_CLUSTER}. Stored in /Users/abel/.eks/${1}" | |
aws eks --region eu-west-1 update-kubeconfig --name ${SRC_CLUSTER} --kubeconfig /Users/abel/.eks/${1} | |
} | |
assume_aws() { | |
unset AWS_ACCESS_KEY_ID | |
unset AWS_SECRET_ACCESS_KEY | |
unset AWS_SESSION_TOKEN | |
unset AWS_SECURITY_TOKEN | |
unset AWS_DEFAULT_REGION | |
unset AWS_REGION | |
unset AWS_PROFILE | |
unset KUBECONFIG | |
mortadelo assume --alias "${1}" --mfa -d 28800 | |
export AWS_PROFILE="${1}" | |
regenerate_kubeconfig "${1}" | |
echo "Switching to kubeconfig /Users/abel/.eks/${1}\n" | |
alias kubectl="kubectl --kubeconfig=/Users/abel/.eks/${1}" | |
alias helm3="helm3 --kubeconfig=/Users/abel/.eks/${1}" | |
kubectl config set-context --current --namespace=${1} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment