pod_override configuration. If a task doesn’t contain a pod_override configuration, it runs using the default Pod as configured in your Deployment resource settings.
This document describes how to configure individual task Pods for different use cases. To configure defaults for all Kubernetes executor task pods, see Configure Kubernetes Pod resources.
Prerequisites
- An Astro Deployment using Astro Runtime version 8.1.0 or later.
Customize a task’s Kubernetes Pod
While you can customize all values for a worker Pod, Astronomer does not recommend configuring complex Kubernetes infrastructure in your Pods, such as sidecars. These configurations have not been tested by Astronomer.
pod_override file.
-
Add the following import to your dag file:
-
Add a
pod_overrideconfiguration to the dag file containing the task. See thekubernetes-clientGitHub for a list of all possible settings you can include in the configuration. -
Specify the
pod_overridein the task’s parameters.
pod_override configuration.
Example: Set CPU or memory limits and requests
You can request a specific amount of resources for a Kubernetes worker Pod so that a task always has enough resources to run successfully. When requesting resources, make sure that your requests don’t exceed the resource limits in your Deployment’s max pod size. The following example shows how you can use apod_override configuration in your dag code to request custom resources for a task:
Use secret environment variables in worker Pods
On Astro Deployments, secret environment variable values are stored in a Kubernetes secret calledenv-secrets. These environment variables are available to your worker Pods, and you can access them in your tasks just like any other environment variable. For example, you can use os.environ[<your-secret-env-var-key>] or os.getenv(<your-secret-env-var-key>, None) in your dag code to access the variable value.
However, if you can’t use Python, or you are using a pre-defined code that expects specific keys for environment variables, you must pull the secret value from env-secrets and mount it to the Pod running your task as a new Kubernetes Secret.
-
Add the following import to your dag file:
-
Define a Kubernetes
Secretin your dag instantiation using the following format: -
Specify the
Secretin thesecret_key_refsection of yourpod_overrideconfiguration. -
In the task where you want to use the secret value, add the following task-level argument:
-
In the executable for the task, call the secret value using
os.environ[env_name].
MY_SECRET is pulled from env-secrets and printed to logs.