vineeth
03/24/2026, 1:21 PMMarvin
03/24/2026, 1:21 PMresearch_prefect_topic
📊 Tools used:
• check_cli_command (2x)
• research_prefect_topic (1x)Mitch Nielsen
03/24/2026, 2:31 PMMarvin
03/24/2026, 2:31 PMMarvin
03/24/2026, 2:31 PMMitch Nielsen
03/24/2026, 2:31 PMMarvin
03/24/2026, 2:31 PMMitch Nielsen
03/24/2026, 2:33 PMMarvin
03/24/2026, 2:34 PMPREFECT_API_DATABASE_CONNECTION_URL (e.g., `postgresql+asyncpg://user:pass@host:5432/dbname`).
- With the Helm chart, you generally inject env vars either directly in values.yaml or (recommended) from a Kubernetes Secret.
Option A — Use an external Postgres (recommended for prod)
1) Create a Secret with your DB URL (and any other env vars)
kubectl create secret generic prefect-server-env \
--from-literal=PREFECT_API_DATABASE_CONNECTION_URL="<postgresql+asyncpg://USER:PASS@DB_HOST:5432/DB_NAME>" \
-n prefect
2) Reference that Secret in values.yaml
# values.yaml
postgresql:
enabled: false # we're using an external DB
server:
# attach the secret to the server pod's env
extraEnvVarsSecret: prefect-server-env
# If you run background services as a separate deployment, also set:
backgroundServices:
runAsSeparateDeployment: true
extraEnvVarsSecret: prefect-server-env
3) Install/upgrade
helm repo add prefect <https://prefecthq.github.io/prefect-helm>
helm repo update
helm upgrade --install prefect-server prefect/prefect-server -n prefect -f values.yaml --create-namespace
Option B — Use the bundled Postgres subchart
If you want the Helm chart to provision Postgres and wire the DB URL automatically:
# values.yaml
postgresql:
enabled: true
auth:
database: prefect
username: prefect
password: change-me # set a strong password or use an existingSecret
# Optional: use an existing secret for the Postgres password
# postgresql:
# enabled: true
# auth:
# existingSecret: my-pg-secret # with key "password"
The chart will construct and export PREFECT_API_DATABASE_CONNECTION_URL for you.
Adding other env vars
- Put non-sensitive values inline:
server:
env:
- name: PREFECT_LOGGING_SERVER_LEVEL
value: "INFO"
- Put sensitive values in a Secret, then reference via server.extraEnvVarsSecret (and backgroundServices.extraEnvVarsSecret if applicable).
Useful links
- Helm chart values reference: prefect-server chart docs
- Helm repo: prefect-helm on GitHub
- Prefect 3 settings (all env vars): Prefect 3 settings
Want me to draft a minimal values.yaml for your setup? If so, let me know:
- Are you using external Postgres or the bundled one?
- Your Kubernetes namespace and the Secret name you prefer
- Any other env vars you want to inject (logging level, UI API URL, etc.)vineeth
03/25/2026, 11:42 AMMarvin
03/25/2026, 11:42 AMMarvin
03/25/2026, 11:45 AMapiVersion: v1
kind: Secret
metadata:
name: my-db-secret
type: Opaque
stringData:
DB_USER: myuser
DB_PASSWORD: mypass
DB_HOST: myhost
DB_NAME: mydb
2) In Prefect UI → Work Pools → your Kubernetes pool → Advanced, ensure the base job template’s first container includes both envFrom (for the secret) and the existing env placeholder. In the job_manifest under spec.template.spec.containers[0], add:
"envFrom": [
{ "secretRef": { "name": "my-db-secret" } }
],
"env": "{{ env }}"
This makes all keys in the secret available as env vars on every flow-run pod, and still lets you add/override vars via job_variables.env.
Option B: Set per-deployment env with job_variables
In code:
from prefect import flow
@flow
def my_flow():
import os
print(os.getenv("DATABASE_URL"))
if __name__ == "__main__":
my_flow.deploy(
name="my-deployment",
work_pool_name="my-kubernetes-pool",
job_variables={
"env": {
"DATABASE_URL": "<postgresql://user:pass@host:5432/dbname>"
}
}
)
This populates the {{ env }} placeholder in the base job template for this deployment.
Option C: Reference individual keys from a Secret in env
If you prefer explicit env entries instead of envFrom:
"env": [
{
"name": "DB_USER",
"valueFrom": { "secretKeyRef": { "name": "my-db-secret", "key": "DB_USER" } }
},
{
"name": "DB_PASSWORD",
"valueFrom": { "secretKeyRef": { "name": "my-db-secret", "key": "DB_PASSWORD" } }
}
]
Notes
- You cannot set flow-run env vars via the Prefect Worker Helm chart; that chart only configures the worker pod. Use it to deploy the worker and optionally to create your Secrets; then reference those Secrets in the work pool base job template as shown.
- The default Kubernetes work pool template already includes "env": "{{ env }}" on the container; keep that so you can pass overrides via job_variables.
- For security, prefer Secrets over putting DB creds inline.
Helpful docs
- Customize base job templates: Customize base job templates
- Customize job variables per deployment: Customize job variables
- Kubernetes integration overview: Prefect Kubernetes integration
- Prefect Helm charts: prefect-helm
Quick clarification to tailor this:
- Do you want these DB env vars applied to all flows in the pool, or only certain deployments?
- Do you already have the DB credentials in a Kubernetes Secret (and what’s the namespace/secret name), or should we show a quick Helm snippet to create it?