Skip to content

Instantly share code, notes, and snippets.

@JohnKDay
Created June 10, 2020 22:53
Show Gist options
  • Save JohnKDay/05b13af6de413a198367b9e7298daf79 to your computer and use it in GitHub Desktop.
Save JohnKDay/05b13af6de413a198367b9e7298daf79 to your computer and use it in GitHub Desktop.
Directly download a TC kubeconfig file
# 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