配置流水线组件的资源配额

概述

配置与 Pipeline 组件相关的资源配额。

用例

  • 调整流水线组件的资源配额
  • 为 TaskRun 创建的 init-containers 和容器设置默认资源配额

前提条件

步骤

步骤 1

编辑 TektonConfig 资源

$ kubectl edit tektonconfigs.operator.tekton.dev config

步骤 2

WARNING

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

修改 spec.pipeline.options.deployments 配置的示例:

apiVersion: operator.tekton.dev/v1alpha1
kind: TektonConfig
metadata:
  name: config
spec:
  pipeline:
    options:
      disabled: false

      configMaps:
        config-defaults:
          data:
            # 添加默认容器资源配额
            default-container-resource-requirements: |
              place-scripts: # 更新 'place-scripts' 容器的资源需求
                requests:
                  memory: "64Mi"
                  cpu: "50m"
                limits:
                  memory: "128Mi"
                  cpu: "100m"

              prepare: # 更新 'prepare' 容器的资源需求
                requests:
                  memory: "64Mi"
                  cpu: "50m"
                limits:
                  memory: "256Mi"
                  cpu: "100m"

              working-dir-initializer: # 更新 'working-dir-initializer' 容器的资源需求
                requests:
                  memory: "64Mi"
                  cpu: "50m"
                limits:
                  memory: "512Mi"
                  cpu: "100m"

              prefix-scripts: # 更新以 'scripts-' 开头容器的资源需求
                requests:
                  memory: "64Mi"
                  cpu: "50m"
                limits:
                  memory: "128Mi"
                  cpu: "100m"

              prefix-sidecar-scripts: # 更新以 'sidecar-scripts-' 开头容器的资源需求
                requests:
                  memory: "64Mi"
                  cpu: "50m"
                limits:
                  memory: "128Mi"
                  cpu: "100m"

              sidecar-tekton-log-results: # 更新 'place-scripts' 容器的资源需求
                requests:
                  memory: "64Mi"
                  cpu: "50m"
                limits:
                  memory: "128Mi"
                  cpu: "100m"

      deployments:

        tekton-pipelines-controller:
          spec:
            replicas: 1
            template:
              spec:
                containers:
                  - name: tekton-pipelines-controller
                    resources:
                      requests:
                        cpu: 500m
                        memory: 512Mi
                      limits:
                        cpu: "1"
                        memory: 1Gi

        tekton-pipelines-remote-resolvers:
          spec:
            replicas: 1
            template:
              spec:
                containers:
                  - name: controller
                    resources:
                      requests:
                        cpu: 200m
                        memory: 256Mi
                      limits:
                        cpu: 500m
                        memory: 512Mi

        tekton-pipelines-webhook:
          spec:
            replicas: 1
            template:
              spec:
                containers:
                  - name: webhook
                    resources:
                      requests:
                        cpu: "500m"
                        memory: 256Mi
                      limits:
                        cpu: "1"
                        memory: 500Mi

        tekton-events-controller:
          spec:
            replicas: 1
            template:
              spec:
                containers:
                  - name: tekton-events-controller
                    resources:
                      requests:
                        cpu: 100m
                        memory: 100Mi
                      limits:
                        cpu: 200m
                        memory: 256Mi

步骤 3

提交配置并等待 Pods 更新。

$ kubectl get pods -n tekton-pipelines -w

NAME                                                    READY   STATUS    RESTARTS   AGE
tekton-pipelines-controller-648d87488b-fq9bc            1/1     Running   0          2m21s
tekton-pipelines-remote-resolvers-79554f5959-cbm6x      1/1     Running   0          2m21s
tekton-pipelines-webhook-5cd9847998-864zf               1/1     Running   0          2m20s
tekton-events-controller-5c97b7554c-m59m6               1/1     Running   0          2m21s

操作结果

你会看到与 Pipeline 相关组件的资源配额配置生效。

$ kubectl get deployments.apps -n tekton-pipelines tekton-pipelines-controller tekton-pipelines-remote-resolvers tekton-pipelines-webhook tekton-events-controller -o yaml | grep 'resources:' -A 6

          resources:
            limits:
              cpu: "1"
              memory: 1Gi
            requests:
              cpu: 500m
              memory: 512Mi
--
          resources:
            limits:
              cpu: 500m
              memory: 512Mi
            requests:
              cpu: 200m
              memory: 256Mi
--
          resources:
            limits:
              cpu: "2"
              memory: 500Mi
            requests:
              cpu: "1"
              memory: 256Mi
--
          resources:
            limits:
              cpu: 200m
              memory: 256Mi
            requests:
              cpu: 100m
              memory: 100Mi

验证Pod 资源配额配置

创建一个TaskRun

$ cat <<'EOF' | kubectl create -f -
apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
  name: hello
  namespace: default
spec:
  taskSpec:
    steps:
      - name: hello
        image: alpine
        command: ["echo", "hello"]
EOF

等待TaskRun 完成

$ kubectl get taskruns.tekton.dev -n default hello

NAME    SUCCEEDED   REASON      STARTTIME   COMPLETIONTIME
hello   True        Succeeded   2m41s       2m28s

查看Pod 资源配额配置

$ kubectl get pods -n default hello-hello-pod -o yaml

apiVersion: v1
kind: Pod
metadata:
  name: hello-pod
  namespace: default
spec:
  containers:
    - image: alpine
      name: step-hello
      resources: {}
  initContainers:
    - name: prepare
      resources:
        limits:
          cpu: 100m
          memory: 256Mi
        requests:
          cpu: 50m
          memory: 64Mi

你可以看到 Pod 中的 initContainers 容器 prepare 的资源配额与 config-defaults ConfigMap 中配置的资源配额匹配。

参考