【问题标题】:Getting 403 error while trying to create Pods using Custom Service Account尝试使用自定义服务帐户创建 Pod 时出现 403 错误
【发布时间】:2020-04-10 13:31:00
【问题描述】:

我在 k8s 集群中创建了以下对象。

  1. 命名空间(testpsp
  2. 自定义 ServiceAccount (testuser)
  3. 角色和角色绑定通过。清单文件

请参阅下面的 yaml 文件以获取 Role 和 RoleBinding 资源。

$ cat developer.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: developer namespace: testpsp rules: - apiGroups: - "" resources: - pods verbs: - get - create - apiGroups: - extensions - apps resources: - deployments - replicasets verbs: - '*'

$ cat developer-binding.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: developer-binding namespace: testpsp roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: developer subjects: - kind: ServiceAccount name: testuser

正如您在上述角色清单文件中看到的,我已将Pod 资源的CREATE 权限 授予testuser 服务帐户。但我仍然收到错误消息。

错误

来自服务器的错误(禁止):创建“hello-pod.yaml”时出错:pods 被禁止:用户“testuser”无法在命名空间“testpsp”中的 API 组“”中创建资源“pods”

这是 Pod yaml 文件。我在这里错过了什么吗?

$ cat hello-pod.yaml apiVersion: v1 kind: Pod metadata: name: hello-pod namespace: testpsp spec: serviceAccountName: testuser containers: - name: hello-kubernetes image: paulbouwer/hello-kubernetes:1.5 ports: - containerPort: 8080

这是我正在运行以创建 Pod 的命令。

$ kubectl --as=testuser -n testpsp create -f hello-pod.yaml

【问题讨论】:

    标签: kubernetes google-kubernetes-engine


    【解决方案1】:

    在排查这个问题时,我注意到在 kubectl 命令的“as”标志中,我们不需要直接提及 ServiceAccount 名称,而是需要使用以下格式

    system:serviceaccount:<namespace_name>:<serviceaccount_name>

    在我的例子中,它看起来像这样 - system:serviceaccount:testpsp:testuser

    之后,它开始正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-22
      • 2021-09-25
      • 1970-01-01
      • 2022-07-18
      • 2021-01-01
      • 1970-01-01
      • 2020-06-04
      • 2017-10-27
      相关资源
      最近更新 更多