我的Kubernetes集群中有一个问题,两个星期前突然出现了。解决给定ServiceAccount的RBAC时,我创建的ClusterRoles不可见。这是重现此问题的最小集。
在default
名称空间中创建相关的ClusterRole,ClusterRoleBinding和ServiceAccount,以有权查看带有此SA的端点。
# 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
特权作为客户。但是如果我能给管理员任何指示,那还是很有帮助的。
提前感谢!
非常感谢您的回答!
事实证明,我们当然永远不会对所发生的事情有最终的了解。集群提供者刚刚重新启动了kube-apiserver,这解决了该问题。
我想是缓存或其他暂时性故障之类的错误,不能定义为可复制的错误。
[为了给将来的读者提供更多数据,该错误发生在由OVH管理的Kubernetes集群上,其特点是将控制平面本身作为pod部署在其一侧的主Kubernetes集群中。