首页 > 解决方案 > 加载命名空间时出错。未经授权:验证您有权访问 Kubernetes 集群

问题描述

我已经使用命令行 eksctl 创建了一个 EKS 集群,并验证了该应用程序工作正常。

但是注意到一个奇怪的问题,当我尝试在 Web 浏览器中访问集群中的节点时,我看到以下错误

Error loading Namespaces
Unauthorized: Verify you have access to the Kubernetes cluster

在此处输入图像描述

我能够看到使用的节点kubectl get nodes

我以管理员用户身份登录。关于如何解决这个问题的任何帮助都会非常棒。谢谢。

标签: amazon-web-serviceskubernetesamazon-eks

解决方案


您需要将 IAM 角色/用户添加到集群的 aws-auth 配置映射

从https://docs.aws.amazon.com/eks/latest/userguide/add-user-role.html采取的基本步骤

kubectl edit -n kube-system configmap/aws-auth
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
data:
  mapRoles: |
    - rolearn: <arn:aws:iam::111122223333:role/eksctl-my-cluster-nodegroup-standard-wo-NodeInstanceRole-1WP3NUE3O6UCF>
      username: <system:node:{{EC2PrivateDNSName}}>
      groups:
        - <system:bootstrappers>
        - <system:nodes>
  mapUsers: |
    - userarn: <arn:aws:iam::111122223333:user/admin>
      username: <admin>
      groups:
        - <system:masters>
    - userarn: <arn:aws:iam::111122223333:user/ops-user>
      username: <ops-user>
      groups:
        - <system:masters>

推荐阅读