Skip to content

Instantly share code, notes, and snippets.

@thbkrkr
Created May 27, 2019 14:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thbkrkr/c9cea078379913d4009fac351b542ef3 to your computer and use it in GitHub Desktop.
Save thbkrkr/c9cea078379913d4009fac351b542ef3 to your computer and use it in GitHub Desktop.
Kubernetes API curl script
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