要深入理解事件监听器的概念、架构和原理,请参考 深入理解事件监听器 文档。
事件监听器是 Tekton Triggers 中的核心资源,负责接收和处理来自外部系统的事件(如 Webhook)。当外部系统触发事件时,事件监听器会根据配置的触发器创建 Kubernetes 资源(如 PipelineRun)。
事件监听器具有以下主要特性:
用于配置事件监听器的 Kubernetes 资源:
serviceType
: 服务类型(NodePort/ClusterIP/LoadBalancer)servicePort
: 服务端口spec
: Pod 模板配置定义一组触发器配置:
name
: 触发器名称interceptors
: 拦截器配置列表bindings
: 触发器绑定配置template
: 触发器模板配置事件监听器支持多种安全配置:
spec.serviceAccountName
指定运行权限。确保指定的 ServiceAccount 配置了相应的权限。为了正确触发管道和任务,事件监听器使用的 ServiceAccount 需要以下权限:
权限 | 资源 | 描述 |
---|---|---|
get, list, watch | configmaps | 读取 ConfigMaps |
get, list, watch | secrets | 读取 Secrets |
get, list, watch | serviceaccounts | 读取 ServiceAccounts |
create, get, list, watch, patch, update | deployments | 管理 Deployments |
create, get, list, watch, patch, update | services | 管理 Services |
create, get, list, watch, patch, update | pods | 管理 Pods |
create, get, list, watch, patch, update | events | 管理 Events |
create | pipelineruns | 创建 PipelineRuns |
create | taskruns | 创建 TaskRuns |
get, list, watch | clustertriggerbindings | 读取 ClusterTriggerBindings |
get, list, watch | triggerbindings | 读取 TriggerBindings |
get, list, watch | clusterinterceptors | 读取 ClusterInterceptors |
get, list, watch | interceptors | 读取 Interceptors |
get, list, watch | triggers | 读取 Triggers |
get, list, watch | triggertemplates | 读取 TriggerTemplates |
get, list, watch | eventlisteners | 读取 EventListeners |
可参照的 ClusterRole:
部署事件监听器需要根据环境的规模和实际网络状况进行规划,以下是如何根据规划不同配置的说明:
在不同的规划场景中,可以使用不同的配置以满足不同的要求。
规模 | 触发器数量 | 资源设置 |
---|---|---|
小规模 | 2(触发器)* 100(命名空间)* 10(管道)= 2,000 触发器/集群 | 中等,两个以上副本 |
中规模 | 2(触发器)* 1,000(命名空间)* 10(管道)= 20,000 触发器/集群 | 中等,两个以上副本,按命名空间部署不同的事件监听器 |
根据环境的优先级和可用网络资源,可以选择不同的网络配置。
网络配置 | 协议 | 描述 |
---|---|---|
官方域名和证书 | https | 通过 ClusterIP + Ingress 设置 TLS 证书 |
自定义域名和证书 | https | 使用自签名证书进行 TLS。注意:工具端配置存在风险,并非所有工具/平台都支持跳过或忽略 TLS 验证。 |
NodePort | http | 通过 NodePort + 集群/节点 IP 设置可访问地址 |
确保有一个命名空间以便于管理事件监听器及其他权限;这里以 tekton-webhooks
为例。
将以下 YAML 保存为 eventlistener.yaml
。
以下 YAML 用于 eventlistener-role.yaml
。
创建一个绑定,使用上述的 ClusterRole 和 ServiceAccount。
需要将 <host> 设置为对应的域名和证书信息。
您可以使用以下 curl
测试配置是否正常。
资源限制:
安全性:
可用性:
监控:
事件未触发管道
权限问题
性能问题