docs/v3/advanced/customize-base-job-templates.mdx
This guide provides comprehensive examples for customizing the Kubernetes base job template. These examples demonstrate common configuration patterns for environment variables, secrets, resource limits, and image pull secrets.
The base job template uses a two-part structure:
{{ variable_name }} syntax to apply them to the Kubernetes job manifestYou can customize the base job template in two ways:
prefect work-pool get-default-base-job-template --type kubernetes
Configure environment variables to pass configuration to your flow runs:
{
"variables": {
"env": {
"title": "Environment Variables",
"description": "Environment variables to set in the container",
"default": {},
"type": "object",
"additionalProperties": {"type": "string"}
}
},
"job_configuration": {
"job_manifest": {
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "prefect-job",
"env": "{{ env }}"
}
]
}
}
}
}
}
}
Reference Kubernetes secrets to inject sensitive data:
{
"variables": {
"secret_name": {
"title": "Secret Name",
"description": "Name of the Kubernetes secret containing credentials",
"default": null,
"type": "string"
}
},
"job_configuration": {
"job_manifest": {
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "prefect-job",
"envFrom": [
{
"secretRef": {
"name": "{{ secret_name }}"
}
}
]
}
]
}
}
}
}
}
}
Configure authentication for private container registries:
{
"variables": {
"image_pull_secrets": {
"title": "Image Pull Secrets",
"description": "Names of Kubernetes secrets for pulling images from private registries",
"default": [],
"type": "array",
"items": {"type": "string"}
}
},
"job_configuration": {
"job_manifest": {
"spec": {
"template": {
"spec": {
"imagePullSecrets": "{{ image_pull_secrets }}"
}
}
}
}
}
}
Set CPU and memory resource constraints:
{
"variables": {
"cpu_request": {
"title": "CPU Request",
"description": "CPU allocation to request for this pod",
"default": "100m",
"type": "string"
},
"cpu_limit": {
"title": "CPU Limit",
"description": "Maximum CPU allocation for this pod",
"default": "1000m",
"type": "string"
},
"memory_request": {
"title": "Memory Request",
"description": "Memory allocation to request for this pod",
"default": "256Mi",
"type": "string"
},
"memory_limit": {
"title": "Memory Limit",
"description": "Maximum memory allocation for this pod",
"default": "1Gi",
"type": "string"
}
},
"job_configuration": {
"job_manifest": {
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "prefect-job",
"resources": {
"requests": {
"cpu": "{{ cpu_request }}",
"memory": "{{ memory_request }}"
},
"limits": {
"cpu": "{{ cpu_limit }}",
"memory": "{{ memory_limit }}"
}
}
}
]
}
}
}
}
}
}
When combining configurations, merge the variables and job_configuration sections. For example, to combine environment variables with resource limits:
{
"variables": {
"env": {
"title": "Environment Variables",
"description": "Environment variables to set in the container",
"default": {},
"type": "object",
"additionalProperties": {"type": "string"}
},
"cpu_request": {
"title": "CPU Request",
"description": "CPU allocation to request for this pod",
"default": "100m",
"type": "string"
},
"memory_request": {
"title": "Memory Request",
"description": "Memory allocation to request for this pod",
"default": "256Mi",
"type": "string"
}
},
"job_configuration": {
"job_manifest": {
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "prefect-job",
"env": "{{ env }}",
"resources": {
"requests": {
"cpu": "{{ cpu_request }}",
"memory": "{{ memory_request }}"
}
}
}
]
}
}
}
}
}
}