docker / docker/buildx

feat(driver/kubernetes): support pod affinity/topology spread via driver-opt or pod template ConfigMap

Open
#3,919 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
4.5k
Forks
682
Avg merge
2d 14h
Merged PRs (30d)
29

Description

Problem

When running multiple parallel docker buildx build invocations with the Kubernetes driver (one builder per image context), all BuildKit pods tend to be scheduled on the same cluster node by the Kubernetes bin-packing scheduler. This causes disk I/O contention during layer extraction — all pods decompress and write the same base image layers simultaneously on shared ephemeral storage, multiplying extraction time by 3–4×.

Example: extracting a 180 MB layer takes ~15s in isolation but ~55s when 3 pods share the same node.

Requested Feature

Expose a mechanism to inject pod affinity / anti-affinity / topology spread constraints into the BuildKit pod spec created by the Kubernetes driver.

Option A: New driver-opt parameters

Add direct driver-opt support for the most common scheduling hints:

--driver-opt=topology-spread.topologyKey=kubernetes.io/hostname
--driver-opt=topology-spread.maxSkew=1
--driver-opt=topology-spread.whenUnsatisfiable=ScheduleAnyway

This would generate a topologySpreadConstraints entry in the pod spec matching the buildkit pods by their app label.

Option B: Pod template ConfigMap (more flexible)

Allow specifying the name of a ConfigMap containing a partial pod spec YAML that gets merged into the generated pod spec:

--driver-opt=podTemplateConfigMap=my-buildkit-template

The ConfigMap (in the same namespace) would contain arbitrary pod spec fields — affinity, topologySpreadConstraints, securityContext, priorityClassName, etc. — giving operators full control without requiring new driver-opt parameters for every Kubernetes scheduling feature.

# ConfigMap data
spec:
  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 100
          podAffinityTerm:
            labelSelector:
              matchLabels:
                app: buildkitd
            topologyKey: kubernetes.io/hostname

Current Workaround

None available without a MutatingAdmissionWebhook or third-party policy engine (e.g. Kyverno), which adds significant operational overhead just to influence BuildKit pod scheduling.

Environment

  • docker buildx version: v0.34.1
  • Kubernetes driver
  • GKE Spot nodes with cluster autoscaler

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Kubernetes driver’s pod-spec generation and driver-opt parsing entry points. Compare the requested direct scheduling options with the ConfigMap approach before choosing a scope, then inspect existing Kubernetes driver tests. Done should include documented configuration, scheduling fields applied to BuildKit pods, and coverage for the selected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.