authentication - 如何为 Kubernetes 创建受限访问令牌
问题描述
我希望有一个令牌用于一段代码,该代码对我的 k8s 集群的访问权限有限,并且只能读取 statefulsets 的副本,如果需要扩展它们,我不希望使用该代码的人成为能够启动新的东西或删除正在运行的东西。这可能吗?如果是,我该怎么做?
解决方案
您需要RBAC(基于角色的访问控制)来完成这项工作。
示例 pod-reader 角色:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["get", "watch", "list"]
将此角色绑定到用户:
apiVersion: rbac.authorization.k8s.io/v1
# This role binding allows "jane" to read pods in the "default" namespace.
kind: RoleBinding
metadata:
name: read-pods
namespace: default
subjects:
- kind: User
name: jane # Name is case sensitive
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role #this must be Role or ClusterRole
name: pod-reader # this must match the name of the Role or ClusterRole you wish to bind to
apiGroup: rbac.authorization.k8s.io
根据您的要求 更改apiGroup
and 。verbs
推荐阅读
- windows - 使用 /etc/hosts 为网站创建别名
- database - 如果我寻找最佳速度,打开数据库文件的模式是什么?
- python-3.x - 如何使用 Python 在 CSV 文件中可变地确定每行的列数?
- python - Keras CNN model with a wrong ROC curve and low accuracy
- android - 调试数据库和 SQLite 文件不一致
- java - 尝试访问 swagger-ui 或 api/api-docs 但出现 404 错误
- google-apps-script - Google Spredsheet - 将文件复制到 TeamDrive 中的另一个文件夹
- azure - 从 ARM 模板中的 resourceId 函数中提取 ResourceName 或 resourceIdentifier
- python - 如何在 Python 中合并重叠区间
- android - 更改通知标题的颜色(Android)