⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Kubernetes Interview Questions Scenario 132 of 207 in Kubernetes
Senior DevOps / SRE [L2] Kubernetes Additional Kubernetes Scenarios (Q101-Q200) Production Scenario [L2]
🎯 Target Role / Context: Kubernetes Scenario #122 (L2) · Additional Kubernetes Scenarios (Q101-Q200)

Q: How do you configure resource requests and limits for init containers?

To configure resource requests and limits for init containers, set resources on each init container just like an app container, but remember the scheduler computes the pod's effective request as the larger of the biggest single.

#Kubernetes #L2 #Container Orchestration #K8s
🎙️ Candidate Opening & Architectural Context
"To <strong>configure resource requests and limits for init containers</strong>, set <code>resources</code> on each init container just like an app container, but remember the scheduler computes the pod's effective request as the larger of the biggest single init container and the sum of all app containers. Init containers run one at a time, so their needs do not add up. Interviewers ask this because a heavy migration init container can quietly inflate a pod's footprint and block scheduling."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: To <strong>configure resource requests and limits for init containers</strong>, set <code>resources</code> on each init container just like an app container, but remember the scheduler computes the pod's effective request as the larger of the biggest single init container and the sum of all app containers. Init containers run one at a time, so their needs do not add up. Interviewers ask this because a heavy migration init container can quietly inflate a pod's footprint and block scheduling.

1️⃣

Mental model: effective request is a max, not a sum

Init containers run sequentially to completion before app containers start, which changes how Kubernetes sums resources.

  • Init side: the effective init request for a resource is the highest request among all init containers, since only one runs at a time.
  • App side: app containers run together, so their requests are added.
  • Pod effective request: the larger of the two values, per resource, plus any configured Pod Overhead. That value is what the scheduler reserves on the node.
  • Limits: the same logic applies to the effective limit. Each container is still throttled or OOM-killed against its own limit while it runs.
  • Sidecars: init containers with restartPolicy: Always (native sidecars, beta and on by default from 1.29) keep running, so their requests are added to the app total instead of being compared as a max.
  • Why this surprises people: the sum-of-containers rule from app containers is widely known, so many teams forget init containers also reserve capacity at scheduling time, even though they exit before the app starts.
Pro Tip: A 2 GiB memory request on a one-off migration init container makes the whole pod need 2 GiB of schedulable memory, even if the app needs 256 MiB.
2️⃣

Hands-on: configure resource requests and limits for init containers

Give every init container explicit values; unset values default to nothing unless a LimitRange injects them.

apiVersion: v1
kind: Pod
metadata:
  name: my-app
  namespace: prod
spec:
  initContainers:
    - name: db-migrate
      image: registry.example.com/migrate:1.4.0
      resources:
        requests: {cpu: 500m, memory: 128Mi}
        limits:   {cpu: "1",  memory: 256Mi}
  containers:
    - name: app
      image: registry.example.com/my-app:1.0.0
      resources:
        requests: {cpu: 200m, memory: 256Mi}
        limits:   {cpu: 500m, memory: 512Mi}
    - name: proxy
      image: registry.example.com/proxy:2.0.0
      resources:
        requests: {cpu: 100m, memory: 64Mi}
        limits:   {cpu: 200m, memory: 128Mi}
  • Set both: requests for scheduling, limits for runtime enforcement. A migration tool that spikes memory should have a limit so it cannot starve neighbours.
  • Worked example: init request 500m CPU and 128Mi memory; app containers requesting 200m plus 100m CPU and 256Mi plus 64Mi memory. Effective CPU is max(500m, 300m) = 500m, effective memory is max(128Mi, 320Mi) = 320Mi.
  • QoS class: init containers participate; for Guaranteed QoS every container, including init, needs requests equal to limits for CPU and memory.
  • Ephemeral storage: init containers that download large artifacts should also set ephemeral-storage requests and limits.
  • Do the arithmetic per resource: CPU, memory and ephemeral storage are each compared separately, so the winning container for CPU can differ from the winner for memory.
Advertisement
3️⃣

Verify what the scheduler actually reserved

Do not compute by hand in production; read it from the cluster.

kubectl -n prod get pod my-app -o jsonpath='{.status.qosClass}{"\n"}'
kubectl -n prod describe pod my-app | sed -n '/Init Containers/,/Conditions/p'
kubectl describe node worker-1 | sed -n '/Allocated resources/,/Events/p'
  • Pod view: kubectl describe pod my-app -n prod lists init and app container resources and the QoS class.
  • Node view: kubectl describe node <node> under Allocated resources and the per-pod table shows the effective request counted against the node.
  • Scheduling failures: a Pending pod with Insufficient cpu or Insufficient memory in events may be caused purely by the init container request.
  • OOM during init: kubectl get pod showing Init:OOMKilled or Init:CrashLoopBackOff means the init limit is too low.
  • Spot-check with a script: list each pod's init and app requests with jsonpath or jq to find pods whose init requests dominate, then right-size them.
4️⃣

Edge cases: LimitRange, quotas and in-place changes

Namespace policy applies to init containers too.

  • LimitRange: type Container defaults, minimums and maximums are applied to init containers, so a default of 1Gi memory can silently raise your effective request.
  • ResourceQuota: the quota counts the pod's effective request, so oversized init containers consume quota too.
  • Immutability: container resources are immutable on a running pod in most versions; in-place pod resize is a newer alpha/beta feature and is version dependent, so check your cluster before relying on it.
  • Native sidecars: if an init container needs to keep running, mark it as a sidecar and size it as a long-running container.
  • Limits versus requests: an init limit higher than the namespace LimitRange max is rejected, and a limit lower than the request is invalid; both errors appear at pod creation.
5️⃣

Production practice: keep init containers lean

Treat init containers as a cost on every pod start.

  • Right-size from data: measure peak usage of migration or download jobs and set limits slightly above it.
  • Move heavy work out: run database migrations as a separate Job rather than in every replica's init container.
  • Policy: enforce that init containers declare resources using the same admission policy as app containers.
  • Observability: watch init container duration and restarts, since slow init delays rollouts.
  • Reuse the same image where possible: smaller, purpose-built init images pull faster and need less ephemeral storage, which shortens pod start-up.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: remember effective request = max(largest init container, sum of app containers). Trim heavy init containers or move migrations to a Job before you add nodes."
⚡ 60-Second Elevator Pitch Talking Points
  • Init containers declare resources like any container, but the pod's effective request is the max of the largest init container and the sum of app containers.
  • I verify with kubectl describe pod and the node's allocated resources, and read Pending events for Insufficient cpu or memory.
  • I enforce resources on init containers through LimitRange and admission policy and move heavy migrations into Jobs.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Adding init container requests to the app total They run sequentially, so the scheduler uses the max, and over-adding leads to wrong capacity planning.
  2. Leaving init containers without limits A runaway download or migration can exhaust node memory and trigger evictions of neighbours.
  3. Ignoring LimitRange defaults The namespace default can inflate the init request without any change to the manifest.
  4. Putting long-running helpers in a normal init container They would block the app forever; use a native sidecar (restartPolicy: Always) or a regular container.
Advertisement
📥 FREE DOWNLOAD · 101-PAGE COMPANION HANDBOOK
Studying for Kubernetes & SRE Technical Rounds?
Download the complete 100-question PDF field guide covering all 11 core modules with offline diagnostic runbooks.
📥 Download PDF (Free) Read Online Guide →
Want more Kubernetes scenarios?
Explore our complete collection of scenario-based Kubernetes interview runbooks.
Browse All Kubernetes Questions →