Last active
December 16, 2021 14:10
-
-
Save amcginlay/90e212216bff98692ce594c058dbeb11 to your computer and use it in GitHub Desktop.
Create an admin service account in the default namespace, then register in kubeconfig and use
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
# rm ~/.kube/config && eksctl utils write-kubeconfig --cluster dev | |
kubectl create serviceaccount admin | |
kubectl create clusterrolebinding admin --serviceaccount default:admin --clusterrole cluster-admin | |
secret_name=$(kubectl get serviceaccount admin -o jsonpath={.secrets[].name}) | |
secret_token=$(kubectl get secret ${secret_name} -o jsonpath={.data.token} | base64 --decode) | |
current_cluster_name=$(kubectl config view --minify -o jsonpath={.clusters[].name}) | |
current_cluster_endpoint=$(kubectl config view --minify -o jsonpath={.clusters[].cluster.server}) | |
kubectl config set-credentials admin --token=${secret_token} | |
kubectl config set-context admin-ctx --user=admin --cluster ${current_cluster_name} | |
kubectl config use-context admin-ctx | |
kubectl config current-context | |
# ------------------------------ | |
# method 1 - "-v 6" reveals the path in use (/api/v1/nodes) | |
kubectl -v 6 get nodes | |
# method 2 | |
kubectl get --raw /api/v1/nodes | \ | |
jq .items[].metadata.name --raw-output | |
# method 3 | |
curl --silent --insecure --header "Authorization: Bearer ${secret_token}" ${current_cluster_endpoint}/api/v1/nodes | \ | |
jq .items[].metadata.name --raw-output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment