Hi all - I'm having trouble passing env variables ...
# prefect-community
l
Hi all - I'm having trouble passing env variables into my kubernetes jobs in Prefect v1.2 (so that they're available while my code is running). I'm running jobs in multiple Kubernetes clusters and need to provide some cluster-specific variables to each flow run. Based on some other posts above, I've tried starting my agent in three different ways - it seems like passing as
--env
at agent startup is a great solution, but the env variable is null for all three of these approaches. 1. passing as arg in
prefect agent kubernetes start --env SERVICES_ENDPOINT=XYZ
2. passing directly as an env var to the agent (dont think this is expected to work) 3. passing as
PREFECT___CLOUD____AGENT__ENV_VARS_
any thoughts on what i could be doing wrong? i tried each of these individually
I can't add the variables @ flow registration time b/c the values of the env vars will vary depending on which cluster the job is running in, so I need to figure out someway to populate them from the agent @ runtime (i think)
b
Hello Luke, you should be able to use option 1 to accomplish what you're trying to do here.
For the
prefect agent kubernetes start --env SERVICES_ENDPOINT=XYZ
command, can you try setting the
'SERVICES_ENDPOINT'
key like so: _'prefix the variable with
PREFECT__
and use two underscores (
__
) to separate each part of the key.'_ Just going off what is mentioned in the docs.
Also, here is a discourse article which covers how to set environment variables on agent startup. The example pertains to secrets, but the env variables you want to capture here can be set in a similar fashion: https://discourse.prefect.io/t/how-to-set-secrets-e-g-github-access-token-on-server/70