Created
June 10, 2020 22:53
-
-
Save JohnKDay/05b13af6de413a198367b9e7298daf79 to your computer and use it in GitHub Desktop.
Directly download a TC kubeconfig file
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
# Set variables | |
export CCP_CP=10.100.51.100 | |
export CCP_LOGIN=admin | |
export CCP_PASS='Cisco123!' #space shouldn't record command in history and thus the password, but you can see it in env, doh! | |
# Get a v3 Token | |
export TOKEN=$(curl --http2 -v -k -X POST -H "Content-Type:application/x-www-form-urlencoded" -d "username=${CCP_LOGIN}&password=${CCP_PASS}" https://"${CCP_CP}/v3/system/login" 2>&1 | awk '$2~/[Xx]-[Aa]uth-[Tt]oken/{gsub("\r","",$3);printf "%s",$3}') | |
[ -n "$TOKEN" ] && echo "${TOKEN}" || echo "Bad LOGIN" | |
# Get the cluster list | |
curl -ksS --request GET -H "X-Auth-Token:$TOKEN" "https://${CCP_CP}/v3/clusters/" | jq -r '.[].name' | |
# export CLUSTER name | |
export CLUSTER=<cluster name from above> | |
# extract the kubeconfig from json | |
curl -ksS --request GET -H "X-Auth-Token:$TOKEN" "https://${CCP_CP}/v3/clusters/" | jq -r ".[]| select(.name == \"${CLUSTER}\")|.kubeconfig" | tee /tmp/kubeconfig-${CLUSTER}.yaml | |
# set the KUBECONFIG env var | |
export KUBECONFIG=/tmp/kubeconfig-${CLUSTER}.yaml | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment