gpt4 book ai didi

logging - 在 kubernetes 中列出集群范围内的事件的狭窄授权

转载 作者:行者123 更新时间:2023-12-02 12:17:02 25 4
gpt4 key购买 nike

我正在尝试让 heapster eventer 在启用了 RBAC 的集群上工作。使用与/heapster 命令相同的角色似乎还不够。

在运行 pod 日志时,会填写如下条目:

Failed to load events: events is forbidden: User "system:serviceaccount:kube-system:heapster" cannot list events at the cluster scope

有没有人知道我的 heapster 服务帐户的正确授权,缺乏管理员权限?

Eventer 部署文档:
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
labels:
k8s-app: eventer
name: eventer
namespace: kube-system
spec:
replicas: 1
selector:
matchLabels:
k8s-app: eventer
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
k8s-app: eventer
spec:
serviceAccountName: heapster
containers:
- name: eventer
image: k8s.gcr.io/heapster-amd64:v1.5.4
imagePullPolicy: IfNotPresent
command:
- /eventer
- --source=kubernetes:https://kubernetes.default
- --sink=log
resources:
limits:
cpu: 100m
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
terminationMessagePath: /dev/termination-log
restartPolicy: Always
terminationGracePeriodSeconds: 30

RBAC:
# Original: https://brookbach.com/2018/10/29/Heapster-on-Kubernetes-1.11.3.html
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: heapster
rules:
- apiGroups:
- ""
resources:
- pods
- nodes
- namespaces
- events
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- deployments
verbs:
- get
- list
- update
- watch
- apiGroups:
- ""
resources:
- nodes/stats
verbs:
- get

集群角色绑定(bind):
# Original: https://github.com/kubernetes-retired/heapster/blob/master/deploy/kube-config/rbac/heapster-rbac.yaml
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: heapster
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: heapster
subjects:
- kind: ServiceAccount
name: heapster
namespace: kube-system

相关问题:
How to propagate kubernetes events from a GKE cluster to google cloud log

最佳答案

以上所有对象对我来说似乎都是正确的。

这只是一种预感,但也许您先创建了 Deployment,然后创建了 ClusterRole 和/或 ClusterBindingRole 和/或 ServiceAccount 本身。确保首先拥有这 3 个,然后删除当前的 heapster Pod(或 Deployment,并在重新创建 Deployment 之前等待 Pod 终止)。

(通过 kubectl create sa heapster -n kube-system 创建 ServiceAccount)

此外,您可以测试 ServiceAccount 是否可以通过以下方式列出事件:

kubectl get ev --all-namespaces --as system:serviceaccount:kube-system:heapster

关于logging - 在 kubernetes 中列出集群范围内的事件的狭窄授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55339863/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com