Created
May 27, 2019 14:24
-
-
Save thbkrkr/c9cea078379913d4009fac351b542ef3 to your computer and use it in GitHub Desktop.
Kubernetes API curl script
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
c8rl() { | |
local cacert=/dev/shm/ca.crt | |
if [[ ! -f $cacert ]]; then | |
SECRET=$(kubectl get serviceaccount default -o json | jq -Mr '.secrets[].name | select(contains("token"))') | |
export TOKEN=$(kubectl get secret ${SECRET} -o json | jq -Mr '.data.token' | base64 -d) | |
export APISERVER=https://$(kubectl -n default get endpoints kubernetes --no-headers | awk '{ print $2 }') | |
kubectl get secret ${SECRET} -o json | jq -Mr '.data["ca.crt"]' | base64 -d > $cacert | |
fi | |
local uri=${1:-version} | |
[[ "$#" > 1 ]] && shift | |
curl -H "Authorization: Bearer $TOKEN" --cacert $cacert -s $APISERVER/$uri $@ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment