실습
Authentication - EKS
kubectl config viewkubectl config view | yq e '.users' -$(kubectl config view \ -o=jsonpath='{.users[0].user.exec.command} {.users[0].user.exec.args[*]}'){ export TOKEN=$($(kubectl config view \ -o=jsonpath='{.users[0].user.exec.command} {.users[0].user.exec.args[*]}') \ | jq -r '.status.token' | grep -oP '(?<=k8s-aws-v1.).*') echo $TOKEN }npm install -g base64-url-cli{ export DECODED_URL=$(base64url decode $TOKEN) echo $DECODED_URL }{ export CLUSTER_NAME=$(kubectl get node \ -o=jsonpath='{.items[0].metadata.labels.alpha\.eksctl\.io\/cluster-name}') echo $CLUSTER_NAME }curl -H "x-k8s-aws-id: $CLUSTER_NAME" $DECODED_URLaws sts get-caller-identity{ export K8S_SERVER=$(kubectl config view \ -o=jsonpath='{.clusters[*].cluster.server}') echo $K8S_SERVER }curl -k -X GET \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ $K8S_SERVER/api/v1/nodes{ export TOKEN=$($(kubectl config view \ -o=jsonpath='{.users[0].user.exec.command} {.users[0].user.exec.args[*]}') \ | jq -r '.status.token') echo $TOKEN }curl -k -X GET \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ $K8S_SERVER/api/v1/nodesaws iam create-user --user-name johnaws iam create-access-key --user-name john > key.txtcat key.txt{ cp ~/.aws/credentials ~/.aws/credentials_backup cp ~/.aws/config ~/.aws/config_backup }{ cat <<EOF >> ~/.aws/credentials [john] aws_access_key_id=$(cat key.txt | jq -r '.AccessKey.AccessKeyId') aws_secret_access_key=$(cat key.txt | jq -r '.AccessKey.SecretAccessKey') EOF cat <<EOF >> ~/.aws/config [profile john] region = ap-northeast-2 EOF }aws sts get-caller-identity --profile johnrm -rf ~/.kube/configkubectl get pod -Aaws eks update-kubeconfig --name $CLUSTER_NAME --profile johnaws iam put-user-policy --user-name john --policy-name eks-admin --policy-document \ '{ "Version": "2012-10-17", "Statement": [ { "Action": [ "eks:DescribeCluster" ], "Resource": "*", "Effect": "Allow" } ] }'{ aws iam list-user-policies --user-name john aws iam get-user-policy --user-name john --policy-name eks-admin }aws eks update-kubeconfig --name $CLUSTER_NAME --profile johnkubectl config viewkubectl get pod -A{ export $(kubectl config view -o=jsonpath='{.users[0].user.exec.env[0].name}={.users[0].user.exec.env[0].value}') $(kubectl config view \ -o=jsonpath='{.users[0].user.exec.command} {.users[0].user.exec.args[*]}') }{ export TOKEN=$($(kubectl config view \ -o=jsonpath='{.users[0].user.exec.command} {.users[0].user.exec.args[*]}') \ | jq -r '.status.token' | grep -oP '(?<=k8s-aws-v1.).*') echo $TOKEN }{ export DECODED_URL=$(base64url decode $TOKEN) echo $DECODED_URL }curl -H "x-k8s-aws-id: $CLUSTER_NAME" $DECODED_URL{ rm -rf ~/.kube/config unset AWS_PROFILE aws eks update-kubeconfig --name $CLUSTER_NAME }
Authorization
Service Account
IAM roles for service accounts
Last updated