【发布时间】:2020-07-14 10:45:36
【问题描述】:
我的 Kubernetes 集群出现问题,两周前突然出现。解析给定 ServiceAccount 的 RBAC 后,我创建的 ClusterRoles 不可见。这是重现问题的最小集合。
在default 命名空间中创建相关的 ClusterRole、ClusterRoleBinding 和一个 ServiceAccount,以有权查看具有此 SA 的 Endpoints。
# test.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: test-sa
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: test-cr
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: test-crb
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: test-cr
subjects:
- kind: ServiceAccount
name: test-sa
namespace: default
$ kubectl apply -f test.yaml
serviceaccount/test-sa created
clusterrole.rbac.authorization.k8s.io/test-cr created
clusterrolebinding.rbac.authorization.k8s.io/test-crb created
如果直接请求,所有对象,尤其是 ClusterRole,都是可见的。
$ kubectl get serviceaccount test-sa
NAME SECRETS AGE
test-sa 1 57s
$ kubectl get clusterrolebinding test-crb
NAME AGE
test-crb 115s
$ kubectl get clusterrole test-cr
NAME AGE
test-cr 2m19s
但是,当我尝试解决此 ServiceAccount 的有效权限时,我得到了以下错误:
$ kubectl auth can-i get endpoints --as=system:serviceaccount:default:test-sa
no - RBAC: clusterrole.rbac.authorization.k8s.io "test-cr" not found
在损坏之前创建的 RBAC 规则运行正常。例如,这里是我几个月前使用 Helm 部署的 etcd-operator 的 ServiceAccount:
$ kubectl auth can-i get endpoints --as=system:serviceaccount:etcd:etcd-etcd-operator-etcd-operator
yes
此集群中 Kubernetes 的版本是1.17.0-0。
我最近还看到新 Pod 的部署非常缓慢,如果有帮助的话,在 StatefulSet 或 Deployment 创建它们后可能需要长达 5 分钟才能开始部署。
您对正在发生的事情有任何见解,甚至我能做些什么吗?请注意,我的 Kubernetes 集群是托管的,所以我对底层系统没有任何控制权,我只是拥有 cluster-admin 作为客户的权限。但无论如何,如果我能给管理员任何指示,那将有很大帮助。
提前致谢!
【问题讨论】:
-
你能添加 kubectl auth can-i --list --as=system:serviceaccount:default:test-sa 和 kubectl auth can-i --list --as=system:serviceaccount 的输出吗:etcd:etcd-etcd-operator-etcd-operator
-
我使用了您的
test.yaml,它在不同版本的 Kubernetes 上都按预期工作。在此过程中是否有任何 Kubernetes 更新?您的 Kubernetes 集群是否在GKE、EKS、AKS上运行?至于部署慢,请看官方文档:Troubleshooting clusters
标签: kubernetes kubectl rbac