Failed to create pod due to config error when using custom images in Tekton
TOC
Problem Description
In the Tekton pipeline, using images provided by the product works correctly, but when using user-defined images, you may encounter TaskRun execution failures.
Error Manifestation
-
TaskRun execution fails with a status of
False, and the reason isCreateContainerConfigError: -
The TaskRun event displays an error message:
-
Relevant pod events show an error message:
Root Cause Analysis
Such issues are typically caused by the following two reasons:
- The image itself has issues.
- The image is incompatible with the Task configuration.
Troubleshooting
If this issue only appears when using custom images, it is recommended to follow these steps for troubleshooting:
-
Verify if the image itself has issues:
-
Check the compatibility of the Task configuration with the image:
- Check if the Task is configured with
runAsNonRoot: true. - Check whether the default user of the image is root or a non-numeric user ID.
- Check if the Task is configured with
Example Task configuration:
Example Dockerfile configuration:
Solution
Option 1: Adjust Image Build Configuration to Set the Default User to a Non-root User
Prerequisites
- Environment and permissions to rebuild the image.
Steps
Refer to Adjust Dockerfile for Task-Compatible Custom Images to modify the Dockerfile configuration.
Option 2: Modify TaskRun or PipelineRun Execution Configuration
Prerequisites
- Permissions to modify TaskRun or PipelineRun.
Steps
-
Add configuration when executing TaskRun separately:
-
Add configuration when executing PipelineRun:
Option 3: Modify Global Tekton Configuration
Prerequisites
- Cluster operation permissions.
- Permissions to modify the TektonConfig resource.
- Note: This configuration will affect all Tasks.
Steps
-
Modify the TektonConfig resource: Increase the following
spec.pipeline.default-pod-templateconfiguration: -
Verify whether the configuration takes effect:
Option 4: Modify Task Definition
Prerequisites
- Permissions to modify the Task.
- Note: This configuration will affect all TaskRuns or PipelineRuns that use this Task.
Steps
-
Method 1: Remove runAsNonRoot configuration:
-
Method 2: Add runAsUser configuration:
Prevent Errors
-
Image Building
- Prioritize using non-root users for building images.
- Use UID 65532 as the non-root user consistently.
- Ensure that the application can run normally with a non-root user.
-
Task Configuration
- Decide whether to enable
runAsNonRootbased on security requirements. - If required, configure
runAsUseraccordingly.
- Decide whether to enable
-
Permission Management
- Follow the principle of least privilege.
- Plan directory permissions in advance.
- Regularly review permission configurations.