0

为了在 kubernetes 集群中进行高可用性测试,我使用了诸如 chaoskube 或 kube-monkey 之类的工具,它会杀死命名空间中的随机 pod 以创建“混乱”并查看系统和应用程序将如何反应。

默认情况下,这些工具需要一个集群角色,以便让其服务帐户列出/杀死集群中所有命名空间的 pod。在我的情况下,我想安装此工具并仅在一个命名空间(命名空间 x)中进行测试是否有任何方法可以限制服务帐户的权限,只是为了授予它从(命名空间 x)列出/杀死 pod 的权限和整个集群?

我已经尝试在(命名空间 x)中创建角色和角色绑定,但仍然有相同的 RBAC 错误,因为服务帐户期望具有集群权限:

"pods is forbidden: User \"system:serviceaccount:x:chaoskube-sa\" cannot list resource \"pods\" in API group \"\ at the cluster scope"

更新:角色和角色绑定这是其服务帐户的默认权限:

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: chaoskube-role
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["list", "delete"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: chaoskube-rolebinding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: chaoskube-role
subjects:
- kind: ServiceAccount
  name: chaoskube-sa
  namespace: x

使用这些配置它工作正常。现在具有特定命名空间的受限权限:

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: chaoskube-role
  namespace: x
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["list", "delete"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: chaoskube-rolebinding
  namespace: x
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: chaoskube-role
subjects:
- kind: ServiceAccount
  name: chaoskube-sa
  namespace: x

它无法列出 pod,并且我收到 RBAC 错误。

4

0 回答 0