vineeth
07/03/2025, 8:19 AMMarvin
07/03/2025, 8:19 AMMarvin
07/03/2025, 8:20 AMyaml
worker:
baseJobTemplate:
spec:
template:
spec:
containers:
- name: prefect-job
env:
- name: MY_ENV_VAR
value: "my-value"
- name: ANOTHER_ENV_VAR
value: "another-value"
# For sensitive values, you can use secrets
- name: SECRET_ENV_VAR
valueFrom:
secretKeyRef:
name: my-secret
key: secret-key
This configuration will:
1. Set environment variables for all flow runs executed by this worker
2. Keep the environment variables out of the Prefect UI
3. Apply consistently across all deployments using this worker
A few important notes:
- The environment variables will be available to all flow runs managed by this worker
- You can mix both direct values and references to Kubernetes secrets
- This approach is more secure than setting variables in the UI since they're managed with your infrastructure code
- The configuration applies at the worker level, so it affects all flows run by this worker
If you need to use Kubernetes secrets, make sure they exist in the namespace where your worker is running. You can create them using:
bash
kubectl create secret generic my-secret --from-literal=secret-key=my-secret-value
This approach is particularly useful when you:
- Want to maintain environment configuration in your infrastructure code
- Need to set environment variables that should be consistent across all flows
- Have sensitive information that should be managed through Kubernetes secrets
- Want to keep environment configuration separate from the Prefect UI
For more details on managing work pools and customizing job variables, you can refer to the Prefect documentation on managing work pools.