狭窄的授权以列出kubernetes中的集群作用域事件

时间:2019-03-25 14:16:07

标签: logging kubernetes heapster

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

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

1 个答案:

答案 0 :(得分:1)

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

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

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

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

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