【问题标题】:Jenkins pipeline k8s deployment failedJenkins 管道 k8s 部署失败
【发布时间】:2021-07-02 19:18:38
【问题描述】:

我正在尝试将我的应用程序部署到 EKS 集群中。当我运行 jenkins 作业时,当我尝试通过 jenkins 部署 yaml 文件时,我可以同时获取运行状态的 kubectl get pod 详细信息,但出现以下错误:

+ kubectl create -f deployment.yaml
Error from server (Forbidden): error when creating "deployment.yaml": deployments.apps is forbidden: User "system:node:ip-10-2-3-4.eu-central-1.compute.internal" cannot create resource "deployments" in API group "apps" in the namespace "default"

创建吊舱

+ kubectl '--kubeconfig=****' '--context=arn:aws:eks:eu-central-1:123456789101:cluster/my-cluster' sh "kubectl auth can-i list pods"
yes

创建部署

+ kubectl '--kubeconfig=****' '--context=arn:aws:eks:eu-central-1:123456789101:cluster/my-cluster' sh "kubectl auth can-i create deployment"
no

【问题讨论】:

    标签: kubernetes amazon-eks


    【解决方案1】:

    这意味着您有权读取/列出 pod 数据,但无权创建 deployment 对象。

    以下是2个例子,检查比较。

    • 第一是阅读规则(你目前拥有的)
    rules:
    - apiGroups: [""]
      #
      # at the HTTP level, the name of the resource for accessing Pod
      # objects is "pods"
      resources: ["pods"]
      verbs: ["get", "list", "watch"]
    
    • 第二个是部署创建权限(verbs: ["**create**"])。很可能你错过了这部分
    rules:
    - apiGroups: ["extensions", "apps"]
      #
      # at the HTTP level, the name of the resource for accessing Deployment
      # objects is "deployments"
      resources: ["deployments"]
      verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
    

    更多选项、示例和说明请查看Using RBAC Authorization

    【讨论】:

    • 嗨 Vit,感谢您的帮助。我是k8世界的新手,请告诉我如何查看您要求我检查的上述规则,我需要使用什么命令。
    • 你能帮帮我吗
    • 检查请回复Jenkins agent for connecting Amazone EKS not work,它应该澄清你很多
    • 检查你的角色,角色绑定。并且请检查Set up Jenkins in a Kubernetes cluster - 我在玩 jenkins 和 EKS 时使用了这篇文章。特别是添加RBAC授权部分
    • 很难在不了解您如何安装集群等的情况下提出建议。
    猜你喜欢
    • 2020-06-14
    • 2022-10-06
    • 2015-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    相关资源
    最近更新 更多