调整子组件的可选配置项

目录

功能概述

通过调整 TektonConfig 资源中各组件的 options 配置,可以实现对子组件的自定义配置。

本文档介绍了 options 支持的配置项,以及如何配置这些项。

使用场景

Tekton 支持通过 TektonConfig 资源部署子组件。该资源在 spec.pipelinespec.triggerspec.hubspec.chainspec.results 字段下均有一个通用配置项 options

通过 options 配置,可以实现:

  • 组件的点位部署
  • 高可用设置的修改
  • 组件副本数的修改
  • 组件资源配额的修改
  • 默认 ConfigMap 配置项的修改

详细可配置项

  • 修改组件的 Deployment 配置,例如:
    • labelsannotations 配置
    • 副本数 replicas
    • 亲和性规则 affinity
    • 优先级类 priorityClassName
    • 节点选择器 nodeSelector
    • 容忍规则 tolerations
    • 拓扑扩散约束 topologySpreadConstraints
    • 运行时类 runtimeClassName
    • volumes
    • 容器 containersinitContainers
      • 资源配额 resources.limitsresources.requests
      • 环境变量 env
      • volumes
      • 执行参数 args
  • 修改组件的 ConfigMap 配置,例如:
    • labelsannotations 配置
    • 更新或新增 data 配置项
  • 修改组件的 Ingress 配置,例如:
    • ingressClassName 用于覆盖默认的 ingressClass 配置
    • rules 用于覆盖默认路由规则
    • tls 用于覆盖默认证书配置
  • 修改组件的 HorizontalPodAutoscaler 自动伸缩配置,例如:
    • 新增该配置
    • 修改 minReplicasmaxReplicas 配置
    • 修改 targetCPUUtilizationPercentage 配置等
  • 修改组件的 StatefulSet 配置
  • 修改组件的 ValidatingWebhookConfigurationMutatingWebhookConfiguration 配置

前置条件

使用该功能前,请确保:

  • 已安装 Tekton Operator 组件
  • 环境中已自动创建 TektonConfig 资源
  • 具备对 TektonConfig 支持的配置项的基本了解

下面是一个典型的 options 配置示例:

apiVersion: operator.tekton.dev/v1alpha1
kind: TektonConfig
metadata:
  name: config
spec:
  targetNamespace: tekton-pipelines
  hub: {}
  chain: {}
  trigger: {}
  pipeline:
    options:
      # 是否禁用 options 配置,默认值为 false。设置为 true 时,options 下的所有配置均不生效。
      disabled: false

      # 配置 ConfigMap 的配置项
      configMaps:
        # 要修改或新增的 ConfigMap 名称
        config-defaults:
          data:
            # 要修改或新增的配置项
            default-container-resource-requirements: |
              place-scripts: # 更新 'place-scripts' 容器的资源需求
                requests:
                  memory: "64Mi"
                  cpu: "50m"
                limits:
                  memory: "128Mi"
                  cpu: "100m"

      # 配置 Deployment 的配置项
      deployments:
        # 要修改的 Deployment 名称
        tekton-events-controller:
          metadata:
            # 要修改的 Deployment 的标签配置
            labels:
              key: value
            # 要修改的 Deployment 的注解配置
            annotations:
              key: value
          spec:
            # 要修改的 Deployment 副本数
            replicas: 1
            # 要修改的模板配置
            template:
              metadata:
                # 要修改的标签配置
                labels:
                  key1: value
                # 要修改的注解配置
                annotations:
                  key1: value
              spec:
                # 要修改的亲和性配置
                affinity:
                  nodeAffinity:
                    requiredDuringSchedulingIgnoredDuringExecution:
                      nodeSelectorTerms:
                        - matchExpressions:
                          - key: kubernetes.io/os
                            operator: In
                            values:
                              - linux

                # 要修改的节点选择器配置
                nodeSelector:
                  kubernetes.io/os: linux

                # 要修改的容忍配置
                tolerations:
                  - effect: NoSchedule
                    key: node-role.kubernetes.io/master
                    operator: Exists

                # priorityClassName: ""
                # topologySpreadConstraints: ""
                # runtimeClassName: ""
                # volumes: []
                # initContainers: []

                containers:
                  # 要修改的容器名称
                  - name: tekton-events-controller
                    # 要修改的资源配额
                    resources:
                      limits:
                        cpu: "1"
                        memory: 1Gi
                      requests:
                        cpu: 500m
                        memory: 512Mi

                    # 要修改的环境变量
                    env:
                      - name: key
                        value: value

                    # 要修改的卷配置
                    # volumes: []

                    # 要新增的执行参数
                    # args: []

      # 要修改或新增的 HorizontalPodAutoscalers 配置
      horizontalPodAutoscalers:
        # 要修改的 horizontalPodAutoscaler 名称
        tekton-pipelines-remote-resolvers:
          metadata:
            # 要修改的注解配置
            # 要修改的标签配置
            labels:
              key: value
            annotations:
              key: value
          spec:
            # 要修改的最小副本数配置
            minReplicas: 1
            # 要修改的最大副本数配置
            maxReplicas: 5
            # 要修改的指标配置
            metrics:
              - resource:
                  name: cpu
                  target:
                    averageUtilization: 50
                    type: Utilization
                type: Resource
              - resource:
                  name: memory
                  target:
                    averageUtilization: 50
                    type: Utilization
                type: Resource
            # 要修改的 scaleTargetRef 配置
            scaleTargetRef:
              apiVersion: apps/v1
              kind: Deployment
              name: tekton-pipelines-remote-resolvers

操作步骤

pipeline 组件为例,介绍如何配置资源配额。

第 1 步

编辑 TektonConfig 资源

$ kubectl edit tektonconfigs.operator.tekton.dev config

第 2 步

WARNING

修改配置可能会触发组件 Pod 的滚动更新,期间服务可能短暂不可用,请在合适时间执行。

修改 spec.pipeline.options.deployments 配置,内容如下:

  • Deployment tekton-events-controller 的副本数改为 2
  • 修改 Deployment tekton-events-controllerresources 配置
apiVersion: operator.tekton.dev/v1alpha1
kind: TektonConfig
metadata:
  name: config
spec:
  targetNamespace: tekton-pipelines
  hub: {}
  chain: {}
  trigger: {}
  pipeline:
    options:
      disabled: false
      deployments:
        tekton-events-controller:
          spec:
            replicas: 2
            template:
              spec:
                containers:
                  - name: tekton-events-controller
                    resources:
                      limits:
                        cpu: "1"
                        memory: 1Gi
                      requests:
                        cpu: 500m
                        memory: 512Mi

第 3 步

提交配置,等待 Pod 更新。

$ kubectl get pods -n tekton-pipelines -l app=tekton-events-controller -w

NAME                                       READY   STATUS    RESTARTS   AGE
tekton-events-controller-fcd56975b-knvzx   1/1     Running   0          20s
tekton-events-controller-fcd56975b-qqprt   1/1     Running   0          31s

操作结果

可以看到 tekton-events-controller 的副本数为 2,且 resources 配置生效。

$ kubectl get deployments.apps -n tekton-pipelines tekton-events-controller -o yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tekton-events-controller
  namespace: tekton-pipelines
spec:
  replicas: 2
  template:
    metadata:
    spec:
      containers:
      - name: tekton-events-controller
        resources:
          limits:
            cpu: "1"
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 512Mi

后续操作

如果需要修改其他组件的配置,可以参考上述步骤修改其他组件的 options 配置。

参考资料