1

我正在尝试让 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

集群角色绑定:

# 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

相关问题: 如何将 kubernetes 事件从 GKE 集群传播到谷歌云日志

4

1 回答 1

1

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

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

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

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

kubectl get ev --all-namespaces --as system:serviceaccount:kube-system:heapster
于 2019-03-25T16:10:47.693 回答