<@ULVA73B9P> how to configure the env varibles lik...
# marvin-ai
v
@Marvin how to configure the env varibles like DB hostname,password in helm chart instead on Prefecr sercer UI
m
🔄 Researching your answer... this may take a while 🔧 Using tool:
research_prefect_topic
📊 Tools used: •
check_cli_command
(2x) •
research_prefect_topic
(1x)
m
@Marvin try again
m
âś… thought for 12.4 seconds
I’m not sure what you want me to try again. Could you share a bit more detail about what you’re working on? Helpful details: - What are you trying to do (and with which Prefect version—assuming 3.x unless you say otherwise)? - How are you running it (Cloud or self-hosted, worker/work pool type)? - The exact command/code you ran - The error/log output you’re seeing If you want me to re-run or re-share specific steps or code from earlier, just paste the last thing you want me to “try again” and I’ll jump on it.
m
@Marvin how to configure the env varibles like DB hostname,password in helm chart instead on Prefecr sercer UI
m
âś… thought for 174.0 seconds
m
m
Got it — you can set DB credentials (and any other Prefect settings) via the Helm chart so nothing needs to be entered in the UI. Quick summary - Prefect 3.x expects a single database URL via the env var
PREFECT_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)
Copy code
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
Copy code
# 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
Copy code
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:
Copy code
# 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:
Copy code
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.)
v
Environment variables to set when starting a flow run. basically i used to give the db details here, so how can give this on helm chart using kind of job template @Marvin
m
âś… thought for 161.8 seconds
Short answer: Helm configures the Prefect worker pod, but your DB env vars need to go on the flow-run pods. In Prefect 3.x you set those on the Kubernetes work pool’s base job template (or per-deployment via job_variables). Helm can create your Kubernetes Secret, but it cannot inject env vars into flow-run pods by itself. What to do - If these env vars should apply to all flows in the pool: add them to the work pool’s base job template. - If they’re per-deployment: pass them as job_variables in your deployment. Key distinction - Worker pod (managed by Helm): long-lived, polls for work. Env here does NOT reach your flows. - Flow-run pod (created per run by the worker): where your code runs; put DB env here via the work pool base job template or deployment job_variables. Option A: Use a Kubernetes Secret and reference it in the base job template (recommended) 1) Create a Secret in your namespace (can be via your own Helm chart):
Copy code
apiVersion: 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:
Copy code
"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:
Copy 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:
Copy code
"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?