只有创建者用户才能从 kubectl 管理 AWS kubernetes 集群(EKS)?

Only the creator user can manage AWS kubernetes cluster (EKS) from kubectl?

我们有两个集群,名为:

  1. MyCluster(我创建的)
  2. OtherCluster(不是我创建的)

其中 "me" 是我自己的 AWS IAM 用户。

我能够使用 kubectl 管理我创建的集群:

>>> aws eks update-kubeconfig --name MyCluster –profile MyUser
>>> kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   172.20.0.1   <none>        443/TCP   59d

但是,我无法管理“OtherCluster”集群(不是我创建的):

>>> aws eks update-kubeconfig --name OtherCluster --profile MyUser
>>> kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
error: the server doesn't have a resource type "svc"

在阅读了在此 github issue 中遇到相同问题的一些人的反馈后,我尝试在最初创建 "OtherCluster".

的用户的上下文中执行此操作

我通过编辑“~/.kube/config”,在“users.user.env”处添加一个“AWS_PROFILE”值来完成此操作。配置文件代表创建集群的用户。

~/.kube/config:

…
users
- name: OtherCluster
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - token
      - -i
      - OtherCluster
      command: aws-iam-authenticator
      env:
      - name: AWS_PROFILE
        value: OTHER_USER_PROFILE
…

这有效:

# ~/.kube/config is currently pointing to OtherCluster

>>> kubectl get svc 
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   172.20.0.1   <none>        443/TCP   1d

我管理集群的时候冒充别人显然不太理想。我更愿意授予我自己的用户访问权限以通过 kubectl 管理集群。 有什么办法可以将管理集群的权限授予原始创建者以外的用户吗?这似乎过于严格

创建 Amazon EKS 集群时,创建集群的 IAM 实体(用户或角色)将作为管理员添加到 Kubernetes RBAC 授权 table。 最初,只有 IAM 用户可以使用 kubectl 调用 Kubernetes API 服务器。

要授予其他 AWS 用户与您的集群交互的能力,您必须在 Kubernetes 中编辑 aws-auth ConfigMap,为您的 ConfigMap 添加一个新的 mapUsers 条目。 This EKS doc涵盖所有流程。

To add an IAM user: add the user details to the mapUsers section of the ConfigMap, under data. Add this section if it does not already exist in the file. Each entry supports the following parameters:

  • userarn: The ARN of the IAM user to add.
  • username: The user name within Kubernetes to map to the IAM user. By default, the user name is the ARN of the IAM user.
  • groups: A list of groups within Kubernetes to which the user is mapped to. For more information, see Default Roles and Role Bindings
    in the Kubernetes documentation.

示例:

apiVersion: v1
data:
  mapRoles: |
    - rolearn: arn:aws:iam::555555555555:role/devel-worker-nodes-NodeInstanceRole-74RF4UBDUKL6
      username: system:node:{{EC2PrivateDNSName}}
      groups:
        - system:bootstrappers
        - system:nodes
  mapUsers: |
    - userarn: arn:aws:iam::555555555555:user/my-new-admin-user
      username: my-new-admin-user
      groups:
        - system:masters

为 EKS 重新配置 kubectl,为新用户使用 AWS 身份验证配置文件,似乎可以解决问题。

aws eks update-kubeconfig --name ${CLUSTER_NAME} --profile ${OTHER_USER}

其中 ${OTHER_USER} 是我尝试授予 EKS 集群访问权限的新用户,而不是最初创建该集群的用户。

我无法解释为什么这个步骤现在对我有用,但在我发布这个问题之前对我不起作用。但希望这对其他人有帮助。