The documentation you are viewing is for Dapr v1.2 which is an older version of Dapr. For up-to-date documentation, see the latest version.

Kubernetes Events binding spec

Detailed documentation on the Kubernetes Events binding component

配置

要设置 Kubernetes 事件绑定,请创建一个类型为 bindings.kubernetes的组件。 请参阅本指南,了解如何创建和应用绑定配置。

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: <NAME>
  namespace: <NAMESPACE>
spec:
  type: bindings.kubernetes
  version: v1
  metadata:
  - name: namespace
    value: <NAMESPACE>
  - name: resyncPeriodInSec
    vale: "<seconds>"

元数据字段规范

字段 必填 绑定支持 详情 示例
namespace Y 输入 要从中读取事件的 Kubernetes 命名空间 "默认值"
resyncPeriodInSec N 从 Kubernetes API 服务器刷新事件列表的时间段。 默认值为 "10" "15"

绑定支持

此组件支持 输入 绑定接口。

输出格式

从绑定中收到的输出是格式 bindings.ReadResponse, 包含 Data 字段包含以下结构:

 {
   "event": "",
   "oldVal": {
     "metadata": {
       "name": "hello-node.162c2661c524d095",
       "namespace": "kube-events",
       "selfLink": "/api/v1/namespaces/kube-events/events/hello-node.162c2661c524d095",
       ...
     },
     "involvedObject": {
       "kind": "Deployment",
       "namespace": "kube-events",
       ...
     },
     "reason": "ScalingReplicaSet",
     "message": "Scaled up replica set hello-node-7bf657c596 to 1",
     ...
   },
   "newVal": {
     "metadata": { "creationTimestamp": "null" },
     "involvedObject": {},
     "source": {},
     "firstTimestamp": "null",
     "lastTimestamp": "null",
     "eventTime": "null",
     ...
   }
 }

有三种不同的事件类型可供选择:

  • 添加 :仅填充 newVal 字段, oldVal 字段为空 v1.Eventeventadd
  • 删除 :仅填充 oldVal 字段, newVal 字段为空 v1.Eventeventdelete
  • 更新 : oldValnewVal 字段都已填充, eventupdate

所需权限

为了消费来自 Kubernetes 的事件,需要使用 Kubernetes 的 [RBAC Auth] 机制将权限分配给用户/组/服务帐户。

角色

其中一个规则需要采用以下格式,以授予 get, watchlist events权限。 API 组可以根据需要进行限制。

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: <NAMESPACE>
  name: <ROLENAME>
rules:
- apiGroups: [""]
  resources: ["events"]
  verbs: ["get", "watch", "list"]

RoleBinding

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: <NAME>
  namespace: <NAMESPACE> # same as above
subjects:
- kind: ServiceAccount
  name: default # or as need be, can be changed
  namespace: <NAMESPACE> # same as above
roleRef:
  kind: Role
  name: <ROLENAME> # same as the one above
  apiGroup: ""

相关链接