Skip to content

Instantly share code, notes, and snippets.

@pydevops
Last active August 21, 2020 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pydevops/6768058ca303ccff6d225249cac08cf5 to your computer and use it in GitHub Desktop.
Save pydevops/6768058ca303ccff6d225249cac08cf5 to your computer and use it in GitHub Desktop.
gke kube-env
curl -s -H "Metadata-flavor: Google" http://169.254.169.254/computeMetadata/v1/instance/attributes/kube-env

curl -s -H 'Metadata-Flavor: Google' 'http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-env' | grep ^KUBELET_CERT | awk '{print $2}' | base64 -d > kubelet.crt
curl -s -H 'Metadata-Flavor: Google' 'http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-env' | grep ^KUBELET_KEY | awk '{print $2}' | base64 -d > kubelet.key
curl -s -H 'Metadata-Flavor: Google' 'http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-env' | grep ^CA_CERT | awk '{print $2}' | base64 -d > apiserver.crt
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl && chmod 755 ./kubectl

KUBERNETES_MASTER_NAME=$(curl -s -H "Metadata-flavor: Google" http://169.254.169.254/computeMetadata/v1/instance/attributes/kube-env | grep ^KUBERNETES_MASTER_NAME | awk '{print $2}')
./kubectl --client-certificate kubelet.crt --client-key kubelet.key --certificate-authority apiserver.crt --server https://${KUBERNETES_MASTER_NAME} get nodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment