Hi guy, has anyone use configmap to pass env var t...
# prefect-server
s
Hi guy, has anyone use configmap to pass env var to Kubernetes agent via helm chart before? If so, how did you do it?
a
@Scarlett King I’m no Helm expert, but it looks like you would have to make some modifications to the deployment files. For example, let’s say that you want to set the value for PREFECT_SERVER__DATABASE__CONNECTION_URL from a ConfigMap - you would have to change this: https://github.com/PrefectHQ/server/blob/master/helm/prefect-server/templates/graphql/deployment.yaml#L55 with:
Copy code
env:
  - name: PREFECT_SERVER__DATABASE__CONNECTION_URL
    valueFrom:
      configMapKeyRef:
        name: your_config_map_name
        key: your_config_map_key
Does this answer your question? Is there a specific value you would like to leverage ConfigMap for? When we look at the agent deployment file, many values here can be set on the
KubernetesRun
directly in your flow, allowing you to set it however you like - using env variables, parameter store, secrets manager, etc..
s
Hi, I’m trying to pass the AZURE_STORAGE_CONNECTION_STRING to Kubernetes agent so I can check out the flow
a
@Scarlett King for that I would recommend PrefectSecret, because ConfigMap is more for configuration data rather than secrets. Also, if you set it as PrefectSecret rather than a normal env variable, you could use it directly as
connection_string_secret
in Prefect’s Azure storage.
Here is how you can set it for Server:
Copy code
export PREFECT__CONTEXT__SECRETS__AZURE_STORAGE_CONNECTION_STRING="YOUR_VALUE"
or set it in the config.toml:
Copy code
[context.secrets]
AZURE_STORAGE_CONNECTION_STRING = "YOUR_VALUE"
s
If I want to set it for server on AKS, where should I do it?
a
@Scarlett King the way I understand it is that you need to set it in your ~/.prefect/config.toml. You’ll also need to set there the external IP of your Azure AKS Server (I believe this would need to be the IP of the Kubernetes node to which this server has been deployed). So your config.toml would need those two settings:
Copy code
[server]
  host = "http://<EXTERNAL-IP>"

[context.secrets]
AZURE_STORAGE_CONNECTION_STRING = "YOUR_VALUE"
It’s described in more detail in this section. LMK if you face any issues with this.
s
Hi, thank you for your reply. May be this is not what I supposed to do but I created a customised image of prefect and set this on the configs.toml there. However, this would mean that the image would have the connection string preloaded on it. Is there a way I can pass the connection string at run time?
a
@Scarlett King you need to have this setting on the agent, because agent downloads the flow code from storage. So if your agent is based on that image, this should work