文章目录
- 版本信息
- 部署准备
- 安装
- 卸载tekton组件
Tektoncd Operator 作为一个 Kubernetes 的扩展,可以方便快捷地在 Kubernetes 集群上安装、升级和管理 Tekton Pipelines、Dashboard、Triggers 等组件。
那么本篇文章介绍在K8S集群中如何通过tekton-operator部署Tekton组件。
版本信息
K8S: v1.28.2
tekton-operator: v0.68.1
部署准备
官方已提供部署文件链接,可自行查找所需版本下载 => https://github.com/tektoncd/operator/releases
https://storage.googleapis.com/tekton-releases/operator/previous/v0.68.1/release.yaml
由于网络原因,我们是无法直接使用官方提供gcr.io
镜像,因此需要提前准备好镜像并push到自己的私有仓库。
并且我们还要替换掉release.yaml
里所有的gcr.io
的镜像:
找到release.yaml
里的tekton-operator-lifecycle容器,在环境变量里添加如下内容。
环境变量名规范是:{前缀}_{容器名/参数名}
- name: IMAGE_PIPELINES_PROXY
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/operator/cmd/kubernetes/proxy-webhook:v0.68.1
- name: IMAGE_PIPELINES_TEKTON_EVENTS_CONTROLLER
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/pipeline/cmd/events:v0.50.3
- name: IMAGE_PIPELINES_WEBHOOK
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/pipeline/cmd/webhook:v0.50.3
- name: IMAGE_PIPELINES_CONTROLLER
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/pipeline/cmd/resolvers:v0.50.3
- name: IMAGE_PIPELINES_TEKTON_PIPELINES_CONTROLLER
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/pipeline/cmd/controller:v0.50.3
- name: IMAGE_PIPELINES_ARGS__ENTRYPOINT_IMAGE
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/pipeline/cmd/entrypoint:v0.50.3
- name: IMAGE_PIPELINES_ARGS__NOP_IMAGE
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/pipeline/cmd/nop:v0.50.3
- name: IMAGE_PIPELINES_ARGS__SIDECARLOGRESULTS_IMAGE
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/pipeline/cmd/sidecarlogresults:v0.50.3
- name: IMAGE_PIPELINES_ARGS__WORKINGDIRINIT_IMAGE
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/pipeline/cmd/workingdirinit:v0.50.3
- name: IMAGE_TRIGGERS_TEKTON_TRIGGERS_CORE_INTERCEPTORS
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/triggers/cmd/interceptors:v0.25.2
- name: IMAGE_TRIGGERS_TEKTON_TRIGGERS_CONTROLLER
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/triggers/cmd/controller:v0.25.2
- name: IMAGE_TRIGGERS_WEBHOOK
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/triggers/cmd/webhook:v0.25.2
- name: IMAGE_TRIGGERS_ARG__EL_IMAGE
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/triggers/cmd/eventlistenersink:v0.25.2
- name: IMAGE_CHAINS_TEKTON_CHAINS_CONTROLLER
value: registry.cloud-devops.com/tekton-releases/github.com/tektoncd/chains/cmd/controller:v0.17.1
- name: IMAGE_JOB_PRUNER_TKN
value: registry.cloud-devops.com/tekton-releases/dogfooding/tkn
在配置文件中,有如下配置。AUTOINSTALL_COMPONENTS
控制tekton-operator在部署完成是否自动部署tekton组件。DEFAULT_TARGET_NAMESPACE
指定组件所属命名空间。
apiVersion: v1
data:
AUTOINSTALL_COMPONENTS: "true"
DEFAULT_TARGET_NAMESPACE: tekton-pipelines
kind: ConfigMap
metadata:
labels:
operator.tekton.dev/release: devel
name: tekton-config-defaults
namespace: tekton-operator
如果AUTOINSTALL_COMPONENTS
为false
,在operator部署成功后,需要我们手动触发tekton组件的部署。
在tekton-operator中有个TektonConfig
的自定义资源,创建其他组件的顶级 CRD。
当我们创建自己所需的 TektonConfig
对象后,operator会根据配置中的profile
字段帮助我们安装相应的其他组件。
Tekton Operator 内置了 3 个 profile:lite、all、basic
Profile | Installed Component | Platform |
---|---|---|
lite | Pipeline | Kubernetes, Openshift |
basic | Pipeline, Trigger, Chains | Kubernetes, Openshift |
all | Pipeline, Trigger, Dashboard, Chains | Kubernetes |
Pipeline, Trigger, Addons, Pipelines as Code, Chains | Openshift |
# To install pipelines, triggers, chains and dashboard (use profile 'all')
$ kubectl apply -f https://raw.githubusercontent.com/tektoncd/operator/main/config/crs/kubernetes/config/all/operator_v1alpha1_config_cr.yaml
apiVersion: operator.tekton.dev/v1alpha1
kind: TektonConfig
metadata:
name: config
spec:
profile: all
targetNamespace: tekton-pipelines # 指定命名空间
pruner:
resources: # 指定可以自动清理的资源
- pipelinerun
- taskrun
keep: 100 # 清理时要保留的最大资源数
schedule: "0 8 * * *" # 清理资源的频率
安装
-
部署tekton-operator
$ kubectl create -f release.yaml
查看部署结果:
$ kubectl get pod -n tekton-operator
-
部署tekton组件
如果AUTOINSTALL_COMPONENTS
为false
执行这个命令。否则跳过,tekton会自动部署组件。$ kubectl create -f operator_v1alpha1_config_cr.yaml
查看结果
$ kubectl get pod -n tekton-pipelines
-
替换dashboard镜像
因为环境变量里还不支持dashboard的镜像替换,这里需要手动更改。$ kubectl get TektonInstallerSet
编辑dashboard-main-deployment-xrlc2
,替换镜像$ kubectl edit TektonInstallerSet dashboard-main-deployment-xrlc2
查看结果
-
访问
Dashboard 的服务默认通过 ClusterIP 方式进行暴露,我们可以创建一个 Ingress 对象或者修改 Service 为 NodePort 方式进行暴露。
卸载tekton组件
卸载tekton其实也很简单,部署时我们知道operator会根据TektonConfig
对象部署组件,那么卸载组件也只需要删除这个对象即可。
# 查询对象
$ kubectl get TektonConfig
删除TektonConfig
对象
$ kubectl delete TektonConfig config
查看结果,各个组件在逐步删除