Kubernetes executor
Execute block runs in separate pods.
Running a block from the code editor, while developing a pipeline, won’t use this executor. Instead, the block will be executed using the same process that the code editor is running on.
If your Mage app is running in a Kubernetes cluster, you can execute the blocks in separate Kubernetes pods with Kubernetes executor.
To configure a pipeline block to use Kubernetes executor, you simply just need to update the executor_type
of the block to k8s
in pipeline’s metadata.yaml:
By default, Mage uses default
as the Kubernetes namespace. You can customize the namespace by setting the KUBE_NAMESPACE
environment variable.
There’re three ways to customize the Kubernetes executor config:
- Add the
executor_config
at block level in pipeline’s metadata.yaml file. Example config: - Add the
k8s_executor_config
to project’s metadata.yaml. Thisk8s_executor_config
will apply to all the blocks that use k8s executor in this project. Example config:
- The kubernetes job name is in this format:
mage-{job_name_prefix}-block-{block_run_id}
. The defaultjob_name_prefix
isdata-prep
. You can customize it in the k8s executor config. You can interpolate the trigger name in thejob_name_prefix
field with the format{trigger_name}
- If you want to use GPU resource in your k8s executor, you can configure the GPU resource in the
k8s_executor_config
likePlease make sure the GPU driver is installed and run on your nodes to use the GPUs. - To further customize the container config of the kubernetes executor, you can specify the
container_config
orjob
in the k8s executor config. Here is the example:
- You can configure the job template by using the
K8S_CONFIG_FILE
environment variable, which should point to the configuration file. Here is the format for the Kubernetes configuration template:
NB: When deploying Mage in a multi-container pod, you need to specify the environment variable MAGE_CONTAINER_NAME
. If this variable is not set, Mage will default to using the first container in the pod. To specify the Mage container, you can use: