Brady Mitchell
07/01/2025, 4:29 PMMarvin
07/01/2025, 4:30 PMMarvin
07/01/2025, 4:30 PMyaml
kubernetes_job:
spec:
template:
spec:
containers:
- name: prefect-job
envFrom:
- configMapRef:
name: your-configmap-name
- secretRef:
name: your-secret-name
# You can also specify individual environment variables if needed
env:
- name: SPECIFIC_VAR
valueFrom:
configMapKeyRef:
name: your-configmap-name
key: specific-key
- name: SPECIFIC_SECRET
valueFrom:
secretKeyRef:
name: your-secret-name
key: specific-secret-key
You can apply this configuration in two ways:
1. Work Pool Level: When creating or updating your Kubernetes work pool:
bash
prefect work-pool create my-k8s-pool \
--type kubernetes \
--base-job-template path/to/base-job-template.yaml
2. Deployment Level: In your prefect.yaml
deployment configuration:
yaml
deployments:
- name: my-deployment
version: null
tags: []
description: null
schedule: null
flow_name: null
entrypoint: null
parameters: {}
work_pool:
name: my-k8s-pool
job_variables:
kubernetes_job:
spec:
template:
spec:
containers:
- name: prefect-job
envFrom:
- configMapRef:
name: your-configmap-name
- secretRef:
name: your-secret-name
A few important notes:
1. Replace your-configmap-name
and your-secret-name
with your actual ConfigMap and Secret names
2. The ConfigMap and Secret must exist in the same namespace as your flow runs
3. The Kubernetes service account used by the worker must have permissions to read the ConfigMap and Secret
4. You can use both envFrom
to load all variables from a ConfigMap/Secret, or env
with specific keys for more granular control
For more details on customizing deployments and infrastructure, you can refer to the Kubernetes infrastructure guide and deployment customization guide.Brady Mitchell
07/01/2025, 4:36 PMMarvin
07/01/2025, 4:36 PMMarvin
07/01/2025, 4:36 PMvariables
section of your base job template to load environment variables using `envFrom`:
json
{
"variables": {
"kubernetes_job": {
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "prefect-job",
"envFrom": [
{
"configMapRef": {
"name": "your-configmap-name"
}
},
{
"secretRef": {
"name": "your-secret-name"
}
}
]
}
]
}
}
}
}
}
}
This configuration will:
1. Load all key-value pairs from the ConfigMap named your-configmap-name
as environment variables
2. Load all key-value pairs from the Secret named your-secret-name
as environment variables
Remember to:
- Replace your-configmap-name
with your actual ConfigMap name
- Replace your-secret-name
with your actual Secret name
- Ensure the ConfigMap and Secret exist in the same namespace as your flow runs
- Verify the Kubernetes service account has the necessary permissions to read these resources
The environment variables will be available to your flow code when it runs in the Kubernetes pod.Brady Mitchell
07/01/2025, 4:41 PMMarvin
07/01/2025, 4:41 PMMarvin
07/01/2025, 4:41 PMjson
{
"variables": {
"kubernetes_job": {
"metadata": {
"labels": {},
"annotations": {}
},
"spec": {
"template": {
"spec": {
"containers": [{
"name": "prefect-job",
"image": "...",
"resources": {
"requests": {},
"limits": {}
},
"env": [],
"envFrom": []
}],
"imagePullSecrets": [],
"serviceAccountName": "..."
}
}
}
}
}
}
I'll create a GitHub issue to request more comprehensive documentation about the base job template structure. In the meantime, you can use the Kubernetes Job specification as a reference for available fields, as the template follows the same structure.
Would you like me to explain any specific parts of the template structure in more detail?Brady Mitchell
07/01/2025, 4:48 PMprefect work-pool get-default-base-job-template -t kubernetes
.
How do I add envFrom to the variables section?Marvin
07/01/2025, 4:48 PMBrady Mitchell
07/01/2025, 4:56 PMMarvin
07/01/2025, 4:59 PMenvFrom
to load environment variables from ConfigMaps and Secrets, you need to add it to the variables
section first, then reference it in the job_configuration
. Here's how:
1. First, add the env_from
property to the variables
section:
json
{
"variables": {
"type": "object",
"properties": {
"env_from": {
"type": "array",
"title": "Container Environment Variables from K8s Reference",
"description": "Define extra environment variables from another kubernetes reference",
"default": [
{
"configMapRef": {
"name": "your-configmap-name"
}
},
{
"secretRef": {
"name": "your-secret-name"
}
}
]
}
// ... other existing properties ...
}
},
"job_configuration": {
// ... other configuration ...
"job_manifest": {
"spec": {
"template": {
"spec": {
"containers": [
{
"envFrom": "{{ env_from }}",
// ... other container configuration ...
}
]
}
}
}
}
}
}
You can set this configuration when creating the work pool:
bash
prefect work-pool create my-k8s-pool \
--type kubernetes \
--base-job-template path/to/template.json
Or update an existing work pool:
bash
prefect work-pool update my-k8s-pool \
--base-job-template path/to/template.json
The envFrom
configuration will be applied to all flow runs in this work pool, loading environment variables from both the ConfigMap and Secret you specified.