繁体   English   中英

kubernetes pods/nodes 被禁止

[英]kubernetes pods/nodes is forbidden

我在本地使用 kubernetes

虽然我使用 kubernetes 构建 gitlab 有一些问题。 我认为这与 serviceaccount 或角色绑定有关。 但找不到正确的方法

我找到了这些帖子

Kubernetes 日志,用户“system:serviceaccount:default:default”无法获取命名空间中的服务

https://github.com/kubernetes/kops/issues/3551

我的错误日志

==> /var/log/gitlab/prometheus/current <==
2018-12-24_03:06:08.88786 level=error ts=2018-12-24T03:06:08.887812767Z caller=main.go:240 component=k8s_client_runtime err="github.com/prometheus/prometheus/discovery/kubernetes/kubernetes.go:372: Failed to list *v1.Node: nodes is forbidden: User \"system:serviceaccount:default:default\" cannot list resource \"nodes\" in API group \"\" at the cluster scope"
2018-12-24_03:06:08.89075 level=error ts=2018-12-24T03:06:08.890719525Z caller=main.go:240 component=k8s_client_runtime err="github.com/prometheus/prometheus/discovery/kubernetes/kubernetes.go:320: Failed to list *v1.Pod: pods is forbidden: User \"system:serviceaccount:default:default\" cannot list resource \"pods\" in API group \"\" at the cluster scope"

问题是由于您的默认服务帐户无权获取集群范围内的节点或 pod。 要解决的最小集群角色和集群角色绑定是:

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: prom-admin
rules:
# Just an example, feel free to change it
- apiGroups: [""]
  resources: ["pods", "nodes"]
  verbs: ["get", "watch", "list"]

---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: prom-rbac
subjects:
- kind: ServiceAccount
  name: default
roleRef:
  kind: ClusterRole
  name: prom-admin
  apiGroup: rbac.authorization.k8s.io

上述集群角色为默认服务帐户提供访问任何命名空间中的任何 Pod 或节点的权限。

您可以更改集群角色为服务帐户提供更多权限,如果您想将访问所有权限授予默认服务帐户,请替换prom-admin resources: ["*"]

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM