Skip to main content
If your Mage app is deployed in a Kubernetes cluster, you can configure the Kubernetes Executor (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}
You can override these defaults at the project level, pipeline level, block level, or with a full Kubernetes job template.

Basic Setup

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.

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:
  1. Environment variable defaults and hardcoded defaults
  2. Project-level k8s_executor_config
  3. Pipeline-level executor_config
  4. Block-level executor_config
For a normal block-level Kubernetes executor run, block settings win over pipeline settings, pipeline settings win over project settings, and project settings win over environment defaults. For 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.
Use when: You want a cluster-wide fallback for jobs that do not define their own Kubernetes resources.

2. Project-Level Configuration

Set k8s_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:
Use when: You want consistent Kubernetes settings across a project, such as default CPU/RAM, namespace, service account, or node scheduling.

3. Pipeline-Level Configuration

Add executor_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.
Use when: You want every block run in one pipeline to inherit the same Kubernetes config, or you run the entire pipeline in one Kubernetes pod with run_pipeline_in_one_process: true.

4. Block-Level Configuration

Add executor_type: k8s and executor_config to a block in the pipeline’s metadata.yaml:
Use when: You only want to:
  • 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 default job_name_prefix is data-prep. You can customize it in the k8s_executor_config. You can interpolate the trigger name in the job_name_prefix field with the format {trigger_name}.
  • GPU Support:
    Make sure GPU device plugins are installed.
  • Custom container & job spec:
Use when: You need specialized resources or scheduling for one expensive block without changing the rest of the pipeline.

5. Full Kubernetes Job Template (maximum control)

Set the K8S_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

Use node_selector to schedule pods on specific nodes based on labels:

Tolerations

Use tolerations to allow pods to be scheduled on tainted nodes:

Affinity Rules

Use affinity for advanced scheduling rules:

Custom Scheduler

Use a custom scheduler for advanced scheduling logic:
Use when: You need full control over pod specs, annotations, volume mounts, and other Kubernetes settings.

Multi-Container Pods

If your Mage deployment runs in a multi-container pod, set the MAGE_CONTAINER_NAME environment variable to specify which container runs Mage:
If not set, Mage defaults to the first container in the pod.

Default config file

You can provide a default K8s executor config file that Mage reads from the path in K8S_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:
Policy fields: 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 when K8S_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):
  1. Block-level executor_config in the pipeline’s metadata.yaml
  2. Pipeline-level executor_config in the pipeline’s metadata.yaml
  3. Project-level k8s_executor_config in the project’s metadata.yaml
  4. Environment variable defaults (listed above)
  5. Hardcoded defaults
When Mage Pro resource usage recommendations suggest new Kubernetes 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.