KubeGlanceDownload
The order of your init containers changes your Pod's CPU request

concepts

The order of your init containers changes your Pod's CPU request

requested: requests.cpu=300m in an exceeded quota error for a Pod you sized at 200m? A sidecar listed before an init container is added to it.

· 9 min read

A native sidecar (an init container with restartPolicy: Always) keeps running while every init container listed after it runs. Kubernetes charges the Pod for that overlap, so the Pod’s effective CPU and memory request depends on the order of spec.initContainers, not just on the numbers in it.

Move the same sidecar from before an ordinary init container to after it and the same Pod goes from 300m to 200m. The official docs give a formula that does not show this, and the symptom never mentions sidecars: it arrives as a ResourceQuota rejection or a Pod stuck in Pending.

The reproduction

A namespace with a requests.cpu quota of 250m:

apiVersion: v1
kind: ResourceQuota
metadata:
  name: cpu-quota
spec:
  hard:
    requests.cpu: 250m

And a Pod with a 100m proxy sidecar, a 200m migration init container and a 100m app:

apiVersion: v1
kind: Pod
metadata:
  name: sidecar-first
spec:
  initContainers:
  - name: proxy
    image: busybox:1.36
    command: ["sleep", "infinity"]
    restartPolicy: Always
    resources:
      requests:
        cpu: 100m
  - name: migrate
    image: busybox:1.36
    command: ["sleep", "5"]
    resources:
      requests:
        cpu: 200m
  containers:
  - name: app
    image: busybox:1.36
    command: ["sleep", "infinity"]
    resources:
      requests:
        cpu: 100m

sidecar-last.yaml is identical except for its name and that migrate is listed above proxy. On a Kubernetes 1.36.1 cluster:

kubectl apply -f sidecar-first.yaml
kubectl apply -f sidecar-last.yaml
kubectl get resourcequota cpu-quota
Error from server (Forbidden): error when creating "sidecar-first.yaml": pods "sidecar-first" is forbidden: exceeded quota: cpu-quota, requested: requests.cpu=300m, used: requests.cpu=0, limited: requests.cpu=250m
pod/sidecar-last created
NAME        REQUEST                   LIMIT   AGE
cpu-quota   requests.cpu: 200m/250m           0s

Same three containers, same three numbers. One is charged 300m and rejected, the other is charged 200m and admitted.

Behind a Deployment you will not see that error at the terminal. kubectl apply succeeds, the Deployment sits at 0/1, and the rejection is an event on the ReplicaSet:

kubectl get events --field-selector reason=FailedCreate -o custom-columns='OBJECT:.involvedObject.name,MESSAGE:.message'
OBJECT           MESSAGE
web-6857b47cbf   Error creating: pods "web-6857b47cbf-rngrk" is forbidden: exceeded quota: cpu-quota, requested: requests.cpu=300m, used: requests.cpu=0, limited: requests.cpu=250m

The fastest check

If requested: in the quota message is higher than the sum you worked out, list the init containers in the order the API server sees them:

kubectl create -f sidecar-first.yaml --dry-run=client -o jsonpath='{range .spec.initContainers[*]}{.name}{"\t"}{.restartPolicy}{"\t"}{.resources.requests.cpu}{"\n"}{end}'
proxy	Always	100m
migrate		200m

Any row with Always above a row without it is a sidecar that will be running while that init container runs, and both are charged together. For a Pod that already exists, run the same jsonpath with kubectl get pod <pod> -o jsonpath=....

To get the number admission will charge without creating anything, use a server-side dry run. It goes through the ResourceQuota admission plugin like a real create does:

kubectl create -f sidecar-first.yaml --dry-run=server
kubectl create -f sidecar-last.yaml --dry-run=server
Error from server (Forbidden): error when creating "sidecar-first.yaml": pods "sidecar-first" is forbidden: exceeded quota: cpu-quota, requested: requests.cpu=300m, used: requests.cpu=0, limited: requests.cpu=250m
pod/sidecar-last created (server dry run)

What the docs say, and why it is wrong

The sidecar containers page (the same text is on the init containers page) defines the Pod’s effective request as pod overhead plus the higher of:

  • the sum of all non-init containers (app and sidecar containers), and
  • the effective init request, which it defines as the highest request among the init containers.

For this Pod that gives max(100m + 100m, 200m) = 200m, in either order. The quota says 300m for one of them. The formula treats a sidecar as if it only ran beside the app containers, but a sidecar starts during the init phase and is still running when every later init container starts. The docs never add it to those init containers.

This was reported as kubernetes/website#57244 on 28 August 2026, with the same 300m rejection. As of 25 September 2026 it is still open, labelled kind/bug and needs-triage, with an assignee and no fix merged. A pull request that would have fixed it, #57373, was closed unmerged by its author 13 minutes after it was opened.

How Kubernetes actually computes it

Admission, the quota controller and the scheduler all call the same function: PodRequests in k8s.io/component-helpers/resource. The quota evaluator calls it at pkg/quota/v1/evaluator/core/pods.go line 406, and the scheduler’s NodeResourcesFit plugin calls it in computePodResourceRequest (pkg/scheduler/framework/plugins/noderesources/fit.go line 323 on release-1.36, 322 on release-1.37). So the order effect shows up in quota, in scheduling and in kubectl describe node.

The algorithm lives in staging/src/k8s.io/component-helpers/resource/helpers.go. On release-1.36 it is inline in AggregateContainerRequests (lines 193–291). On release-1.37 the same loop was extracted into aggregateContainerResourcesByFn (lines 235–289) so limits can share it; the arithmetic did not change. The reproduction above is verified on 1.36.1; the 1.37 behaviour is source-checked on release-1.37. Line numbers below are 1.36 / 1.37:

  1. Sum the app containers (1.36 lines 207–229, 1.37 lines 241–251). With one 100m app container, the total starts at 100m.
  2. Walk spec.initContainers in declaration order, carrying two running values: restartableInitContainerReqs, the sidecars started so far, and initContainerReqs, the highest init-phase figure seen so far (1.36 lines 231–232, 1.37 lines 253–254).
  3. A sidecar (1.36 lines 259–265, 1.37 lines 272–278) is added to the Pod total, because it runs for the whole life of the Pod, and added to the running sidecar sum. The candidate for the init-phase peak is that sidecar sum.
  4. An ordinary init container (1.36 lines 266–271, 1.37 lines 279–284) is charged as its own request plus the sidecars already started above it.
  5. Keep the peak with maxResourceList after each init container (1.36 line 276, 1.37 line 285).
  6. The effective request is the higher of the Pod total and the init peak (1.36 line 279, 1.37 line 287). PodRequests then adds pod overhead.

The code comment spells it out: InitContainerUse(i) = sum(Resources of restartable init containers with index < i) + Resources of i-th init container (1.36 line 237, 1.37 line 259). Index less than i is the whole story. A sidecar counts against the init containers below it, never against those above it.

Worked through for both orders:

StepSidecar first (proxy, migrate)Sidecar last (migrate, proxy)
App containerstotal = 100mtotal = 100m
Init 1proxy (sidecar): total = 200m, sidecars = 100m, peak = 100mmigrate: 200m + 0m sidecars = 200m, peak = 200m
Init 2migrate: 200m + 100m sidecars = 300m, peak = 300mproxy (sidecar): total = 200m, sidecars = 100m, peak = max(200m, 100m) = 200m
Resultmax(200m, 300m) = 300mmax(200m, 200m) = 200m
The peak moves because the sidecar is running during every init container listed after it. Kubernetes charges the overlap.

That is not a bug in Kubernetes. With the sidecar first, the kubelet really does run proxy and migrate at the same time, because a sidecar only has to be started, not finished, before the next init container begins. For those seconds the Pod needs 300m, and admission reserves what the Pod needs at its peak. The code is right. The docs are wrong.

Limits use the same shape: AggregateContainerLimits on release-1.36 (lines 426–469), and the shared aggregateContainerResourcesByFn on release-1.37 (line 421). A limits.cpu or limits.memory quota shows the same order effect, and memory is summed exactly like CPU.

It changes scheduling too

The scheduler charges the node the same number. To see it without a quota, scale the same Pod up on an 18-CPU node: a 9-CPU sidecar, a 9500m init container and the same 100m app. Sidecar last, the effective request is max(9 + 0.1, 9.5) = 9.5 CPU. Sidecar first, it is max(9.1, 9 + 9.5) = 18.5 CPU, more than the whole node. Verified on 1.36.1:

kubectl get pods
kubectl get events --field-selector reason=FailedScheduling -o custom-columns='OBJECT:.involvedObject.name,MESSAGE:.message'
NAME                READY   STATUS    RESTARTS   AGE
big-sidecar-first   0/2     Pending   0          15s
big-sidecar-last    2/2     Running   0          15s
OBJECT              MESSAGE
big-sidecar-first   0/1 nodes are available: 1 Insufficient cpu. no new claims to deallocate, preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.

The Pod that did schedule is charged the order-dependent figure on the node, not the sum of its containers:

kubectl describe node | grep -E 'Namespace|big-sidecar'
  Namespace                   Name                                                 CPU Requests  CPU Limits  Memory Requests  Memory Limits  Age
  k22order                    big-sidecar-last                                     9500m (52%)   0 (0%)      0 (0%)           0 (0%)         15s

On a real cluster this rarely looks like “more than the node”. It looks like a Pod that fits on paper, stays Pending with Insufficient cpu, and schedules the moment someone reorders the manifest. The general case is covered in how to fix a Pending pod.

Fixing it

Decide whether the overlap is real. The extra charge is correct if the init container needs the sidecar. The common case is a mesh proxy or a Cloud SQL proxy that a migration job talks through. Moving the sidecar below the init container would bring the charge down and break the migration, because the proxy would not be running yet. In that case, raise the quota or size the node for the true peak.

If it does not need the sidecar, list it first. An init container that only copies files or renders config does not care whether the proxy is up. Put it above the sidecar and it is charged on its own. Nothing else about the Pod changes: the sidecar still starts before the app containers and still runs for the life of the Pod.

Right-size the init container for the overlap. An init container’s request is often copied from the app container. If migrate runs for five seconds, it rarely needs 200m reserved beside a running proxy, and cutting it to what it really uses brings the peak down in either order.

Watch stacked sidecars. Each sidecar adds to every ordinary init container listed after it, and sidecars add up (the running sum at 1.36 line 264, 1.37 line 277). Two 100m sidecars ahead of a 500m init container put a 700m peak on that step.

Preventing it

  • Do not add up container requests to find a Pod’s cost. Most dashboards and quota spreadsheets sum spec.containers and get both orders wrong. The only reliable figure is the requested: value in a --dry-run=server against a namespace with a quota, or the Pod’s line in kubectl describe node once it is running.
  • Review initContainers order as a resource change. Moving an entry in that list can change the Pod’s request with no change to any request field, which a diff reviewer will miss unless they know to look.
  • Check where injected sidecars land. A mutating webhook that adds a native sidecar decides its position in initContainers, and that position decides which of your init containers pay for it. Look at the admitted Pod, not your manifest.

For what a CPU request actually does once the Pod is on the node, see CPU requests vs limits: what each one writes to the cgroup.

The quota rejection lives on the ReplicaSet, not the Deployment you applied. KubeGlance is a native Kubernetes client for iPhone and iPad, with a full Mac app on the same core — pod detail, events and workload state straight from your kubeconfig.

Get KubeGlance
#sidecar #init-containers #requests #resourcequota #scheduling

The Kubernetes dashboard that fits in your pocket

KubeGlance is a native Kubernetes client for iPhone and iPad — the real dashboard, not a companion — with a full Mac app on the same core. Pods, workloads, logs and events, straight from your kubeconfig.

Download KubeGlance