首页 > 解决方案 > 使用代入的 IAM 角色从 EKS pod 访问远程 EKS 集群

问题描述

我已经阅读了本指南,以允许在我的 EKS 集群上运行的一个 pod 使用 kubectl 访问远程 EKS 集群。

我目前正在我的集群中使用amazon/aws-cli运行一个 pod ,安装一个服务帐户令牌,它允许我根据上面的指南承担一个使用 kubernetes RBAC 配置的 IAM 角色。我已确保通过运行正确承担了角色,aws sts get-caller-identity确实如此。

我现在已经安装了 kubectl 并像这样配置了 kube/config -

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: <redacted>
    server: <redacted>
  name: <cluster-arn>
contexts:
- context:
    cluster: <cluster-arn>
    user: <cluster-arn>
  name: <cluster-arn>
current-context: <cluster-arn>
kind: Config
preferences: {}
users:
- name: <cluster-arn>
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - --region
      - us-east-2
      - eks
      - get-token
      - --cluster-name
      - <cluster-name>
      - --role
      - <role-arn>
      command: aws
      env: null

但是,我尝试使用 kubectl 执行的每个操作都会导致此错误 -
error: You must be logged in to the server (Unauthorized)

我不知道我配置错了什么,如果有任何关于如何获得更详细错误消息的想法,我将不胜感激。

标签: amazon-web-serviceskubernetesamazon-iamamazon-eks

解决方案


如果 AWS CLI 已经在使用您想要的角色的身份,则不需要在 kubeconfig 参数中指定--role& 。<role-arn>

通过保留它们,您的角色aws sts get-caller-identity将需要具有sts:AssumeRole该角色的权限<role-arn>。如果它们是相同的,那么角色需要能够假设自己——这是多余的。

所以我会尝试从中删除这些参数kubeconfig.yml,看看它是否有帮助。


推荐阅读