首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在库伯奈特问题上,有哪些医生需要获得什么权利才能做一件事?

在库伯奈特问题上,有哪些医生需要获得什么权利才能做一件事?
EN

Stack Overflow用户
提问于 2022-08-12 02:11:07
回答 1查看 39关注 0票数 0

这里是我的第一个ServiceAccount,ClusterRole和ClusterRoleBinding

代码语言:javascript
复制
---
# Create namespace
apiVersion: v1
kind: Namespace
metadata:
  name: devops-tools
---
# Create Service Account
apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: devops-tools
  name: bino

---
# Set Secrets for SA
# k8s >= 1.24 need to manualy created
# https://stackoverflow.com/a/72258300
apiVersion: v1
kind: Secret
metadata:
  name: bino-token
  namespace: devops-tools
  annotations:
    kubernetes.io/service-account.name: bino
type: kubernetes.io/service-account-token

---
# Create Cluster Role
# Beware !!! This is Cluster wide FULL RIGHTS
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: devops-tools-role
  namespace: devops-tools
rules:
  - apiGroups:
        - ""
        - apps
        - autoscaling
        - batch
        - extensions
        - policy
        - networking.k8s.io
        - rbac.authorization.k8s.io
    resources:
      - pods
      - componentstatuses
      - configmaps
      - daemonsets
      - deployments
      - events
      - endpoints
      - horizontalpodautoscalers
      - ingress
      - jobs
      - limitranges
      - namespaces
      - nodes
      - pods
      - persistentvolumes
      - persistentvolumeclaims
      - resourcequotas
      - replicasets
      - replicationcontrollers
      - serviceaccounts
      - services
    verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
---
# Bind the SA to Cluster Role
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: devops-tools-role-binding
subjects:
- namespace: devops-tools
  kind: ServiceAccount
  name: bino
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: devops-tools-role
---

当我使用它来创建NameSpace、部署和服务时,它可以工作。但当我试图创造善意时,它却失败了(抱怨“没有权利”):进入。

然后我试着添加

代码语言:javascript
复制
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: devops-tools-role-binding-admin
subjects:
- namespace: devops-tools
  kind: ServiceAccount
  name: bino
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin

现在‘比诺’可以做所有的事情。

我的问题是:是否有任何关于“apiGroups”和“资源”需要分配的文档,以便一个服务帐户可以做一些事情(而不是所有的事情)?

由衷地

-比诺-

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-12 02:45:05

可以运行此命令来确定资源的apiGroup

代码语言:javascript
复制
kubectl api-resources

你会看到这样的情况:

代码语言:javascript
复制
NAME        SHORTNAMES    APIVERSION              NAMESPACED   KIND
ingresses   ing           networking.k8s.io/v1    true         Ingress

所以您需要将其添加到rules of您的ClusterRole中。

代码语言:javascript
复制
- apiGroups:
  - "networking.k8s.io/v1"
  resources:
  - "ingresses"
  verbs:
  - "get"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73328578

复制
相关文章

相似问题

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