3.3. 使用自定义 SCC 和自定义服务帐户运行管道运行和任务
当使用与默认 pipelines 服务帐户关联的 pipelines-scc 安全性上下文约束(SCC)时,管道运行和任务运行 Pod 可能会面临超时问题。这是因为在默认的 pipelines-scc SCC 中,fsGroup.type 参数设置为 MustRunAs。
有关 pod 超时的更多信息,请参阅 BZ#1995779.
为避免 pod 超时,您可以创建一个自定义 SCC,并将 fsGroup.type 参数设置为 RunAsAny,并将它与自定义服务帐户关联。
作为最佳实践,使用自定义 SCC 和自定义服务帐户来运行管道运行和任务运行。这种方法具有更大的灵活性,在升级过程中修改默认值时不会中断运行。
流程
定义自定义 SCC,并将
fsGroup.type参数设置为RunAsAny:示例:自定义 SCC
apiVersion: security.openshift.io/v1 kind: SecurityContextConstraints metadata: annotations: kubernetes.io/description: my-scc is a close replica of anyuid scc. pipelines-scc has fsGroup - RunAsAny. name: my-scc allowHostDirVolumePlugin: false allowHostIPC: false allowHostNetwork: false allowHostPID: false allowHostPorts: false allowPrivilegeEscalation: true allowPrivilegedContainer: false allowedCapabilities: null defaultAddCapabilities: null fsGroup: type: RunAsAny groups: - system:cluster-admins priority: 10 readOnlyRootFilesystem: false requiredDropCapabilities: - MKNOD runAsUser: type: RunAsAny seLinuxContext: type: MustRunAs supplementalGroups: type: RunAsAny volumes: - configMap - downwardAPI - emptyDir - persistentVolumeClaim - projected - secret创建自定义 SCC:
示例:创建
my-sccSCC$ oc create -f my-scc.yaml创建自定义服务帐户:
示例:创建一个
fsgroup-runasany服务帐户$ oc create serviceaccount fsgroup-runasany将自定义 SCC 与自定义服务帐户关联:
示例:将
my-sccSCC 与fsgroup-runasany服务帐户关联$ oc adm policy add-scc-to-user my-scc -z fsgroup-runasany如果要将自定义服务帐户用于特权任务,您可以通过运行以下命令将
privilegedSCC 与自定义服务帐户关联:示例:将
privilegedSCC 与fsgroup-runasany服务帐户关联$ oc adm policy add-scc-to-user privileged -z fsgroup-runasany在管道运行和任务运行中使用自定义服务帐户:
示例:Pipeline 使用
fsgroup-runasany自定义服务帐户运行 YAMLapiVersion: tekton.dev/v1 kind: PipelineRun metadata: name: <pipeline-run-name> spec: pipelineRef: name: <pipeline-cluster-task-name> taskRunTemplate: serviceAccountName: 'fsgroup-runasany'示例:任务使用
fsgroup-runasany自定义服务帐户运行 YAMLapiVersion: tekton.dev/v1 kind: TaskRun metadata: name: <task-run-name> spec: taskRef: name: <cluster-task-name> taskRunTemplate: serviceAccountName: 'fsgroup-runasany'