executor_type: k8s) to run each block in its own Kubernetes pod.
Defaults in Mage Pro:
- Namespace:
default - Job name format:
mage-data-prep-block-{block_run_id}
Basic Setup
To configure a pipeline block to use Kubernetes executor, you simply just need to update theexecutor_type of the block to k8s in pipeline’s metadata.yaml:
default as the Kubernetes namespace. You can customize the namespace by setting the KUBE_NAMESPACE environment variable.
Configuration Methods
You can configure Kubernetes Executor in several places. Mage builds the effective config by deep-merging the less specific config first, then applying more specific config on top:- Environment variable defaults and hardcoded defaults
- Project-level
k8s_executor_config - Pipeline-level
executor_config - Block-level
executor_config
run_pipeline_in_one_process: true,
Mage uses the pipeline-level Kubernetes executor and merges only project-level
and pipeline-level settings because the whole pipeline runs in one pod.
Most nested dictionaries are merged, so you can set broad defaults at the
project level and override only the keys that need to change at the pipeline or
block level. Resource requests and limits are applied to the job container after
the pod template is built, so executor_config.resource_requests and
executor_config.resource_limits take precedence over container.resources.
1. Environment Variable Defaults
Use environment variables to set default resource requests, resource limits, and service account for all Kubernetes executor jobs. These values are only applied when a more specific project, pipeline, or block config does not set the same resource group.2. Project-Level Configuration
Setk8s_executor_config in the project’s metadata.yaml to apply defaults to
all blocks and pipeline runs that use the Kubernetes Executor in that project:
3. Pipeline-Level Configuration
Addexecutor_type: k8s and executor_config to the pipeline’s
metadata.yaml. Pipeline-level config applies to the pipeline executor when
run_pipeline_in_one_process: true; it also acts as a shared default for block
runs in that pipeline before block-level overrides are applied.
run_pipeline_in_one_process: true.
4. Block-Level Configuration
Addexecutor_type: k8s and executor_config to a block in the pipeline’s
metadata.yaml:
- Run certain blocks in the Kubernetes executor
- Override the Kubernetes executor config for specific blocks
-
The Kubernetes job name is in this format:
mage-{job_name_prefix}-block-{block_run_id}. The defaultjob_name_prefixisdata-prep. You can customize it in thek8s_executor_config. You can interpolate the trigger name in thejob_name_prefixfield with the format{trigger_name}.
-
GPU Support:
Make sure GPU device plugins are installed.
-
Custom container & job spec:
5. Full Kubernetes Job Template (maximum control)
Set theK8S_CONFIG_FILE environment variable to the path of a YAML
configuration file. This is the raw job template for Kubernetes executor jobs.
Use K8S_DEFAULT_CONFIG_PATH instead when you want a reusable policy that
merges with user config as described in Default config file.
Example template:
Node Scheduling Configuration
Node Selector
Usenode_selector to schedule pods on specific nodes based on labels:
Tolerations
Usetolerations to allow pods to be scheduled on tainted nodes:
Affinity Rules
Useaffinity for advanced scheduling rules:
Custom Scheduler
Use a custom scheduler for advanced scheduling logic:Multi-Container Pods
If your Mage deployment runs in a multi-container pod, set theMAGE_CONTAINER_NAME environment variable to specify which container runs Mage:
Default config file
You can provide a default K8s executor config file that Mage reads from the path inK8S_DEFAULT_CONFIG_PATH environment variable. The file is loaded as a policy and merged with block-level and project-level config. Use this to enforce cluster-wide defaults (e.g. resource limits, service account) without editing every project.
Helm chart: When deploying Mage Pro with the Mage Helm chart, configure the default via k8sExecutorConfig in values.yaml. The chart creates a ConfigMap from your config, mounts it into the control-plane (and workspace pods), and sets K8S_DEFAULT_CONFIG_PATH automatically. Do not set the env var manually when using the chart. See Using Helm for details. For non-Helm deployments, set the env var and ensure the file exists at that path (e.g. via your own ConfigMap or volume mount).
File format:
The file must exist at the given path on the Mage control-plane. Use a ConfigMap or volume mount to provide it. When workspaces are created, only the K8s default config file is injected (volume + volume mount + env var) so workspace pods can read it; see Workspaces.
Priority when merging default file with user config
The default file is merged with the combined user config (block + pipeline + project). The effective priority order (who wins for a given key) depends on
enforce:
So when
enforce: true, the policy has the highest priority; when enforce: false, block, pipeline, and project config are higher and the policy only supplies missing values.
Environment Variables Reference
General Configuration
Resource Usage Metrics
In Mage Pro, completed Kubernetes executor runs can store CPU and memory usage summaries for the run detail Resources tab and the pipeline monitoring dashboard. Mage uses Prometheus first whenK8S_RESOURCE_USAGE_PROMETHEUS_URL is configured; otherwise it uses the
Kubernetes Metrics API fallback when available.
Pipeline-level recommendations are available in Mage Pro after completed K8s
executor runs have stored CPU or memory samples. Mage calculates the suggested
resource_requests and resource_limits from observed usage, then shows the
values in the pipeline monitoring page so you can copy them into
executor_config or k8s_executor_config.
How recommendations are calculated:
Mage marks the recommendation as
low confidence when the run has fewer than
three samples or an OOM warning, medium when enough samples exist from the
Kubernetes Metrics API fallback, and high when Prometheus provides at least
six samples. Prometheus samples are queried with
K8S_RESOURCE_USAGE_PROMETHEUS_STEP_SECONDS and Mage can wait once after a run
completes, controlled by
K8S_RESOURCE_USAGE_PROMETHEUS_COMPLETION_DELAY_SECONDS, before retrying sparse
completed runs. When unset, the completion delay defaults to
K8S_RESOURCE_USAGE_PROMETHEUS_STEP_SECONDS.
See Monitoring with Prometheus for Prometheus query behavior and authentication details.
Default Resource Configuration
These environment variables set default resource limits and requests for all K8s executor jobs. They are applied when a project-level, pipeline-level, or block-level configuration does not specify resource requests or limits.
Priority order without a default config file (highest to lowest):
- Block-level
executor_configin the pipeline’smetadata.yaml - Pipeline-level
executor_configin the pipeline’smetadata.yaml - Project-level
k8s_executor_configin the project’smetadata.yaml - Environment variable defaults (listed above)
- Hardcoded defaults
resource_requests or resource_limits, apply the values at the narrowest
level you want to tune: block-level for one block, pipeline-level for all runs
of one pipeline, or project-level for all Kubernetes executor jobs in the
project.