调整子组件的可选配置项

功能概述

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

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

使用场景

Tekton 通过 TektonConfig 资源支持子组件的部署。该资源在 spec.pipelinespec.triggerspec.hubspec.chainspec.result 字段下都提供了一个通用配置项 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:
      # Whether to enable options configuration, default value is false. When set to true, all configurations under options will not take effect.
      disabled: false

      # Configure ConfigMap's configurations
      configMaps:
        # Name of the ConfigMap to be modified or added
        config-defaults:
          data:
            # Configuration items to be modified or added
            default-container-resource-requirements: |
              place-scripts: # updates resource requirements of a 'place-scripts' container
                requests:
                  memory: "64Mi"
                  cpu: "50m"
                limits:
                  memory: "128Mi"
                  cpu: "100m"

      # Configure Deployment's configurations
      deployments:
        # Name of the Deployment to be modified
        tekton-events-controller:
          metadata:
            # Labels configuration of the Deployment to be modified
            labels:
              key: value
            # Annotations configuration of the Deployment to be modified
            annotations:
              key: value
          spec:
            # Number of replicas of the Deployment to be modified
            replicas: 1
            # Template configuration to be modified
            template:
              metadata:
                # Labels configuration to be modified
                labels:
                  key1: value
                # Annotations configuration to be modified
                annotations:
                  key1: value
              spec:
                # Affinity configuration to be modified
                affinity:
                  nodeAffinity:
                    requiredDuringSchedulingIgnoredDuringExecution:
                      nodeSelectorTerms:
                        - matchExpressions:
                          - key: kubernetes.io/os
                            operator: In
                            values:
                              - linux

                # Node selector configuration to be modified
                nodeSelector:
                  kubernetes.io/os: linux

                # Tolerations configuration to be modified
                tolerations:
                  - effect: NoSchedule
                    key: node-role.kubernetes.io/master
                    operator: Exists

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

                containers:
                  # Name of the container to be modified
                  - name: tekton-events-controller
                    # Resource quotas to be modified
                    resources:
                      limits:
                        cpu: "1"
                        memory: 1Gi
                      requests:
                        cpu: 500m
                        memory: 512Mi

                    # Environment variables to be modified
                    env:
                      - name: key
                        value: value

                    # Volume configuration to be modified
                    # volumes: []

                    # Execution arguments to be added
                    # args: []

      # HorizontalPodAutoscalers configuration to be modified or added
      horizontalPodAutoscalers:
        # Name of the horizontalPodAutoscaler to be modified
        tekton-pipelines-remote-resolvers:
          metadata:
            # Annotations configuration to be modified
            # Labels configuration to be modified
            labels:
              key: value
            annotations:
              key: value
          spec:
            # MinReplicas configuration to be modified
            minReplicas: 1
            # MaxReplicas configuration to be modified
            maxReplicas: 5
            # Metrics configuration to be modified
            metrics:
              - resource:
                  name: cpu
                  target:
                    averageUtilization: 50
                    type: Utilization
                type: Resource
              - resource:
                  name: memory
                  target:
                    averageUtilization: 50
                    type: Utilization
                type: Resource
            # scaleTargetRef configuration to be modified
            scaleTargetRef:
              apiVersion: apps/v1
              kind: Deployment
              name: tekton-pipelines-remote-resolvers

操作步骤

以下以 pipeline 组件为例,说明如何配置资源配额。

Step 1

编辑 TektonConfig 资源

$ kubectl edit tektonconfigs.operator.tekton.dev config

Step 2

WARNING

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

按如下方式修改 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

Step 3

提交配置并等待 Pods 更新完成。

$ 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 配置。

参考资料