Sizing the Airflow Kubernetes Executor: Pod Resources, Parallelism and Where the Limits Really Are

The Kubernetes executor has no worker fleet to size. Each task instance gets its own pod. That sounds like the sizing problem has gone away. It has not. It has moved to three places: the resources you request per pod, the concurrency limits Airflow enforces before a pod is created, and the cluster that has to schedule those pods.

This post walks through each, in the order we check them on an estate.

Start with measurement, not defaults

Before changing anything, collect two numbers per task family over a few weeks:

  • Peak memory and CPU of the task container (from your cluster metrics, not from Airflow).
  • Wall-clock time from queued to running. This is pod scheduling plus image pull plus interpreter start-up.

If the second number is larger than the work the task does, no amount of resource tuning will help. Those tasks are candidates for a different approach (see the end).

1. Pod resources: requests, limits and the default pod

Most estates run every task with one pod_template_file and one set of resources. That is the first thing to break up.

A reasonable shape:

  • A small default template. Something like 250m CPU and 512Mi memory requests for tasks that only call an API or submit work elsewhere.
  • Per-task overrides with executor_config and pod_override for the few tasks that load data in-process.
from kubernetes.client import models as k8s

heavy = {
    "pod_override": k8s.V1Pod(
        spec=k8s.V1PodSpec(
            containers=[
                k8s.V1Container(
                    name="base",
                    resources=k8s.V1ResourceRequirements(
                        requests={"cpu": "1", "memory": "4Gi"},
                        limits={"memory": "4Gi"},
                    ),
                )
            ]
        )
    )
}

# on the task:  executor_config=heavy

The container must be named base or the override does not apply to the Airflow container.

Two rules we hold to:

  • Memory request equals memory limit. Memory is not compressible. A pod that bursts past its request on a crowded node is the usual cause of an OOMKilled task with exit code 137 that passes on retry. Setting request equal to limit makes the failure deterministic and the sizing honest.
  • Set a CPU request, think hard before setting a CPU limit. CPU limits throttle. A throttled task takes longer, holds its pool slot longer, and the apparent problem becomes concurrency. Requests are what the scheduler uses for placement.

Caveat: per-task overrides are code in your DAGs. On an estate with hundreds of DAGs, put them in a small shared module with named sizes (small, medium, large) so that nobody invents a fourth number.

2. Concurrency: the limits that apply before any pod exists

Airflow decides how many tasks may run before Kubernetes is involved. These settings interact, and the lowest one wins:

  • [core] parallelism: maximum running task instances across the whole deployment. The default is 32. Estates that moved to Kubernetes and never touched this wonder why 40 free nodes sit idle.
  • [core] max_active_tasks_per_dag: per-DAG ceiling.
  • Pools: per-resource ceilings. These matter more than the other two on a mixed estate.
  • [kubernetes_executor] worker_pods_creation_batch_size: how many pods the executor asks for per scheduler loop. If you launch bursts at midnight and pods trickle in, this is worth raising, with the scheduler's CPU in view.

A practical order of work:

  1. Work out the cluster's real task capacity: allocatable memory on the nodes you give to Airflow divided by your typical pod request, not node count times a guess.
  2. Set parallelism to a value at or just under that capacity.
  3. Use pools to protect the things that are actually scarce: the warehouse, a rate-limited API, a database. Cluster capacity is rarely what you are protecting.

Caveat: setting parallelism above what the cluster can hold does not make things faster. Pods go Pending, the executor counts them as running, and you get timeouts that look like Airflow bugs.

3. The cluster side

When task queue time is high and Airflow limits are not the cause, look here:

  • Autoscaler lag. If nodes are added on demand, the first pods of a burst wait for node provisioning. Either keep a warm baseline or accept the delay and schedule the burst earlier.
  • Image pull time. Large images with no node-local cache cost tens of seconds per cold pod. Slim the image, or pin the image tag so nodes cache it. Avoid imagePullPolicy: Always on a tag that never changes.
  • Namespace quotas. A ResourceQuota on the Airflow namespace produces pod creation failures that the executor retries. Check the scheduler logs for Forbidden responses.
  • Scheduler resources. The scheduler talks to the Kubernetes API for every pod. An undersized scheduler pod, or a slow API server, shows up as delayed state changes. Size it from its own metrics, and do not forget DAG parsing competes for the same CPU.

4. Pod cleanup and failure visibility

Leave delete_worker_pods at its default of true in normal operation. Set delete_worker_pods_on_failure only while debugging and turn it off again; failed pods accumulate and count against quota and API load. Ship task logs to remote storage so you do not need the pod to read them.

5. When per-task pods are the wrong choice

If a large share of your tasks run for under about 30 seconds, you are paying pod start-up on each. Options, each with a cost:

  • Run short tasks on a long-lived executor alongside Kubernetes. Airflow supports configuring multiple executors and selecting one per task. This adds a second thing to operate.
  • Batch tiny tasks into fewer, larger ones. This reduces visibility and makes retries coarser.
  • Move to the Celery executor with fixed workers. You regain fast start-up and lose per-task isolation and scale-to-zero.

None of these is correct for every estate. We have left Kubernetes executors in place where the tasks were long, memory-hungry and uneven, which is the case it suits.

A short checklist

  1. Measure peak memory and queue-to-running time per task family.
  2. Split the default pod into three named sizes.
  3. Memory request equals limit; CPU request set; CPU limit usually unset.
  4. Raise parallelism to match computed cluster capacity, and use pools for scarce external resources.
  5. Check autoscaler lag, image pulls, quotas and scheduler size before blaming Airflow.
  6. Re-measure after one week of production runs.

The real-estate caveat

Numbers from other people's estates, including ours, will mislead you. Task memory depends on your data volumes, which change quarterly. Re-check sizes after any large source change. On managed platforms such as MWAA and Cloud Composer, you do not control the executor in this way, and the sizing questions are different. If you are running the Kubernetes executor on Airflow 2.x, note that sizing work carried over to 3.x should be re-verified after the upgrade, since pod launch and task execution changes there can shift both start-up time and memory.