AWS EKS 执行 kubectl 时 error: You must be logged in to the server (Unauthorized)

在 AWS 上创建好 EKS 后,想要在本地用  kubectl 来管理 EKS,必须用 aws eks update-kubeconfig 来更新本地的 ~/.kube/config 文件或者 KUBECONFIG 环境变量指向的别的配置文件。

比如说你创建 EKS 的用户在本地 ~/.aws/credentials 中的 profile 是 my-aws-profile, 那么完整的 update-kubeconfig 命令就是

$ aws eks --profile my-aws-profile --region us-east-1 update-kubeconfig --name myeks-cluster
Updated context arn:aws:eks:us-east-1:069762108088:cluster/myeks-cluster in /Users/yanbin/.kube/config

再来执行 kubectl get pods 如果出现错误 error: You must be logged in to the server (Unauthorized),肯定是因为你使用的 awscli 命令比较老(到底有多老呢?在 github 上已经无法追溯了,大概是 1.16.266 之前的)。大约生成的 ~/.kube/config 文件末尾像下面那样 阅读全文 >>