首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法作为ServiceAccount进行部署

无法作为ServiceAccount进行部署
EN

Stack Overflow用户
提问于 2022-07-30 12:47:11
回答 1查看 53关注 0票数 0

我试图访问另一个名称空间中的部署,并具有以下ServiceAccountClusterRoleClusterRoleBinding

代码语言:javascript
复制
apiVersion: v1
kind: ServiceAccount
metadata:
  name: tekton-triggers-example-sa
  namespace: tekton-pipelines
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
    name: tekton-pipeline-sa
rules:
    - apiGroups: [""]
      resources: ["secrets", "services", "deployments", "pods"]
      verbs: ["get", "watch", "list", "create", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
    name: tekton-pipeline-permissions
    namespace: tekton-pipelines
subjects:
    - kind: ServiceAccount
      name: tekton-triggers-example-sa
      namespace: tekton-pipelines
roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: ClusterRole
    name: tekton-pipeline-sa

有了这个,我可以得到除了deployments以外的一切

代码语言:javascript
复制
kubectl auth can-i get secrets --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes
kubectl auth can-i get services --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes
kubectl auth can-i get deployments --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no
kubectl auth can-i get pods --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes

如果我删除绑定,我什么也得不到,这是有道理的

代码语言:javascript
复制
kubectl delete -f rbac/binding.yaml 
clusterrolebinding.rbac.authorization.k8s.io "tekton-pipeline-permissions" deleted

kubectl auth can-i get secrets --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no
kubectl auth can-i get services --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no
kubectl auth can-i get deployments --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no
kubectl auth can-i get pods --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no

如果我再次应用它,我可以访问除了deployments以外的所有东西

代码语言:javascript
复制
kubectl apply -f rbac/binding.yaml 
clusterrolebinding.rbac.authorization.k8s.io/tekton-pipeline-permissions created
kubectl auth can-i get secrets --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes
kubectl auth can-i get services --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes
kubectl auth can-i get deployments --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no
kubectl auth can-i get pods --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes

因此,在我看来,绑定对于除deployments之外的所有资源都是有效的。

谁知道我错了什么,为什么我不能进入部署?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-30 13:05:47

您的ClusterRole应该是:

代码语言:javascript
复制
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: tekton-pipeline-sa
rules:
- apiGroups: [""]
  resources: ["secrets", "services", "pods"]
  verbs: ["get", "watch", "list", "create", "delete"]
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["get", "watch", "list", "create", "delete"]

一个部署将有一些apiVersion: apps/v1。它属于apiGroups apps。这里有豆荚、秘密或服务的地方将其设置为v1,因此在appGroups ""中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73175745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档