写入 Tekton Task 结果时超出结果大小限制

问题描述

当某个 Task 步骤向 Task result 写入相对较大的内容时,输出可能会因大小限制而失败。

错误表现

  • Pod 日志显示 termination message 溢出(由于默认 4 KB 上限,result 过大):

    2025/10/15 03:22:24 ERROR Error while substituting step artifacts: error="Termination message is above max allowed size 4096, caused by large task result."
    2025/10/15 03:22:24 Termination message is above max allowed size 4096, caused by large task result.

根本原因分析

默认情况下,Tekton Pipelines 通过容器的 termination message 来捕获 Task results,而 Kubernetes 将其限制为 4 KB。 这实际上将单个 Task 可用的 result 大小上限限制为 4096 bytes。

为了突破该上限,Tekton 支持从 sidecar logs 读取 results,并对 每个 result 应用可配置的 max-result-size。

故障排查

TIP

以下说明假设您已默认将 Tekton Pipeline 安装到 tekton-pipelines 命名空间中。

如果您将其安装到其他命名空间中,请将 tekton-pipelines 替换为您的命名空间。

以下是配置 result 大小限制的步骤:

  1. 通过设置 spec.pipeline.results-from 和 spec.pipeline.max-result-size 来编辑 TektonConfig 资源,如下所示:

    apiVersion: operator.tekton.dev/v1alpha1
    kind: TektonConfig
    metadata:
      name: config
    spec:
      pipeline:
        # Use sidecar logs instead of termination messages
        results-from: sidecar-logs
        # Result size in bytes (example: 64 KiB). Max is 1,572,863 bytes.
        max-result-size: 65536
  2. feature-flags ConfigMap 将自动更新。

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: feature-flags
      namespace: tekton-pipelines
    data:
      results-from: sidecar-logs
      max-result-size: "65536"
  3. 由于已启用 results-from: sidecar-logs 功能,您需要为 controller 配置日志访问权限:

    技术说明:此配置允许 controller 从 Pod 日志中检索 results 信息。有关详细信息,请参阅 Tekton official documentation。

    kubectl apply -f - <<EOF
    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: tekton-pipelines-controller-pod-log-access
      labels:
        app.kubernetes.io/component: controller
        app.kubernetes.io/instance: default
        app.kubernetes.io/part-of: tekton-pipelines
    rules:
      - apiGroups: [""]
        resources: ["pods/log"]
        verbs: ["get"]
    ---
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: tekton-pipelines-controller-pod-log-access
      labels:
        app.kubernetes.io/component: controller
        app.kubernetes.io/instance: default
        app.kubernetes.io/part-of: tekton-pipelines
    subjects:
      - kind: ServiceAccount
        name: tekton-pipelines-controller
        namespace: tekton-pipelines
    roleRef:
      kind: ClusterRole
      name: tekton-pipelines-controller-pod-log-access
      apiGroup: rbac.authorization.k8s.io
    EOF
  4. 无需手动重启任何组件,变更将自动生效。

相关内容