【问题标题】:Kubernetes: ClusterRole created in the cluster are not visible during rbac checksKubernetes:在集群中创建的 ClusterRole 在 rbac 检查期间不可见
【发布时间】: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 集群是否在 GKEEKSAKS 上运行?至于部署慢,请看官方文档:Troubleshooting clusters

标签: kubernetes kubectl rbac


【解决方案1】:

非常感谢您的回答!

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

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

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

【讨论】:

    猜你喜欢
    • 2021-09-12
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    • 2016-05-02
    • 2018-09-19
    • 2019-05-19
    相关资源
    最近更新 更多