首页 > 解决方案 > Kubernetes:在集群中创建的 ClusterRole 在 rbac 检查期间不可见

问题描述

我的 Kubernetes 集群有一个问题,两周前突然出现。解析给定 ServiceAccount 的 RBAC 后,我创建的 ClusterRoles 不可见。这是重现问题的最小集合。

在命名空间中创建相关的 ClusterRole、ClusterRoleBinding 和一个 ServiceAccountdefault以有权查看具有此 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作为客户的权限。但无论如何,如果我能给管理员任何指示,那将有很大帮助。

提前致谢!

标签: kuberneteskubectlrbac

解决方案


非常感谢你的回答!

事实证明,我们肯定永远不会知道最终世界会发生什么。集群提供者刚刚重新启动了 kube-apiserver,这解决了这个问题。

我想出现了一些问题,比如缓存或其他暂时性故障,不能定义为可重现的错误。

为了给未来的读者提供更多数据,错误发生在 OVH 管理的 Kubernetes 集群上,它们的特殊性是将控制平面本身作为部署在他们身边的主 Kubernetes 集群中的 pod 运行。


推荐阅读