Intro
Kubernetes Deployments ensure that a specified number of pod replicas are running at any given time, and they provide declarative updates, scaling, and rollbacks. ReplicationControllers exist for legacy workloads, but Deployments are the recommended replacement for new applications. Capacity planning for a Deployment is the process of estimating the CPU and memory each pod needs, determining how many replicas are required to handle expected traffic, and then translating those estimates into Kubernetes resource requests, limits, and namespace quotas. When done well, capacity planning prevents both under-provisioning - which leads to slow responses, failed health checks, and pod evictions - and over-provisioning, which wastes compute and cloud budget.
This guide takes a hands-on approach. We walk through a concrete example: planning capacity for a stateless web application managed by a Deployment. We start by documenting the cluster environment, then build a safe configuration step by step, verify it under load, and finally explore common failure modes with recovery procedures. An operations checklist at the end gives you a repeatable process you can adapt to your own services.
Version and Environment Inventory
Before making any capacity changes, document your cluster version, node topology, and the current state of any existing Deployment. This baseline helps you understand what APIs are available and what resources you can actually schedule.
Cluster and Kubernetes Version
Run the following command to see both client and server versions:
kubectl version
Example output:
Client Version: v1.29.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.28.3
Note the server version. Deployments are part of the apps/v1 API and are available in all supported Kubernetes releases. If your server is older than 1.26, some command syntax or metrics endpoints may differ.
Node Topology and Capacity
List your nodes and their allocatable resources with a custom columns command:
kubectl get nodes -o custom-columns='NAME:.metadata.name,CPU:.status.allocatable.cpu,MEMORY:.status.allocatable.memory,STORAGE:.status.allocatable.ephemeral-storage'
Example output:
NAME CPU MEMORY STORAGE
node-1 4 8Gi 100Gi
node-2 4 8Gi 100Gi
node-3 4 8Gi 100Gi
This cluster has a total allocatable capacity of 12 CPU cores and 24Gi of memory. When you size pods, the sum of all resource requests across all namespaces must fit within this total, or pods will remain Pending.
Existing Deployment Configuration
If you already have a Deployment, inspect its current replica count and pod template:
kubectl describe deployment <deployment-name> -n <namespace>
Look for the Replicas field, the Pod Template section (especially resources.requests and resources.limits), and any recent events. If no Deployment exists yet, you will create one from scratch as shown below.
Prerequisites for This Guide
- A running Kubernetes cluster with
kubectlconfigured and authenticated. - Permission to create and modify Deployments, Pods, and ResourceQuotas in the target namespace.
- A basic understanding of Kubernetes resource requests and limits.
- A non-production namespace or test cluster (such as minikube or kind) for safe experimentation before applying changes to production.
- The Kubernetes metrics-server installed if you want to use
kubectl topfor live resource usage. If it is not installed, you can still usekubectl describe nodeor external monitoring.
Safe Configuration Path
Building a capacity plan requires knowing your application's real resource consumption. We will first estimate single-pod resource usage, then set requests and limits, choose an initial replica count, and apply the manifest with guardrails.
Step 1: Measure Your Application's Resource Needs
Do not guess. You need data on how much CPU and memory a single instance of your application uses under typical and peak load. Three practical ways to gather this data:
- Load test in isolation: Deploy one pod with generous limits, send representative traffic, and observe metrics.
- Use historical metrics: Query Prometheus or another monitoring system for an existing deployment of the same application.
- Use live observation: Run
kubectl top podrepeatedly while the application is under normal traffic.
For this guide, assume we have measured our web application and found:
- CPU: approximately 0.2 cores (200 millicores) at idle, rising to 0.5 cores under moderate load.
- Memory: approximately 128Mi at idle, rising to 256Mi under moderate load.
These numbers are the foundation for all subsequent decisions.
Step 2: Set Resource Requests and Limits
Resource requests tell the Kubernetes scheduler how much CPU and memory a pod is guaranteed. Limits cap how much a pod can consume. If a container exceeds its CPU limit, Kubernetes throttles it. If it exceeds its memory limit, the container is killed with an OOM error.
A safe starting policy is to set requests equal to the observed average usage, and limits to the peak usage plus a 20 percent buffer. For our example numbers:
- CPU request:
200m(0.2 cores) - CPU limit:
600m(0.6 cores) - peak 0.5 cores plus 20 percent - Memory request:
128Mi - Memory limit:
300Mi- peak 256Mi plus about 17 percent
If your application is bursty or you have strict latency requirements, you may want to set the CPU request closer to the limit. For memory, never set the request too low, because the scheduler uses the request for bin packing; if many pods oversubscribe memory, nodes can hit memory pressure and evict pods.
Step 3: Choose an Initial Replica Count
The number of replicas depends on expected traffic and the capacity of a single pod. Start with enough replicas to handle twice your baseline load plus one extra for failover.
For our example, we expect 100 requests per second (RPS) at baseline. Load testing shows one pod can handle about 50 RPS at a reasonable latency. Therefore we need at least 2 pods to serve the baseline. For high availability and some headroom, we will start with 3 replicas. This gives us capacity for 150 RPS, which is 1.5 times baseline, and keeps the application available if one pod fails.
Step 4: Create the Deployment Manifest
Below is a complete manifest for our example. Save it as web-deployment.yaml.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
namespace: production
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.25
resources:
requests:
cpu: 200m
memory: 128Mi
limits:
cpu: 600m
memory: 300Mi
ports:
- containerPort: 80
Apply the manifest:
kubectl apply -f web-deployment.yaml
Expected output:
deployment.apps/web-deployment created
Step 5: Enforce Resource Quotas
To prevent a misconfigured Deployment from consuming all cluster resources, create a ResourceQuota in the namespace. Quotas also force every pod to define requests and limits, which is a best practice.
Example quota for the production namespace:
apiVersion: v1
kind: ResourceQuota
metadata:
name: production-quota
namespace: production
spec:
hard:
pods: '10'
requests.cpu: '2'
requests.memory: '4Gi'
limits.cpu: '4'
limits.memory: '8Gi'
Apply it:
kubectl apply -f quota.yaml
Now the namespace can hold at most 10 pods and 2 CPU cores of requests. Our Deployment with 3 pods uses 600m CPU requests and 384Mi memory requests, well within the quota. If someone tries to scale to 15 replicas, the API server rejects the pod creation because the quota would be exceeded.
Step 6: Test Basic Scaling Behavior
Before relying on the Deployment, confirm it maintains the desired replica count. Delete one pod and watch it get recreated:
kubectl delete pod -l app=web -n production
kubectl get pods -n production -w
You will see output similar to the following:
NAME READY STATUS RESTARTS AGE
web-deployment-xxxxx 1/1 Terminating 0 5m
web-deployment-yyyyy 1/1 Running 0 5m
web-deployment-zzzzz 1/1 Running 0 5m
web-deployment-aaaaa 0/1 Pending 0 0s
web-deployment-aaaaa 0/1 ContainerCreating 0 0s
web-deployment-aaaaa 1/1 Running 0 1s
After a few seconds, the pod count returns to 3. This confirms the Deployment controller is functioning.
Verification and Diagnostics
After deployment, verify that the Deployment is healthy and that your capacity estimates are accurate. Use the following commands and expected outputs as a checklist.
Check Deployment Status
kubectl describe deployment web-deployment -n production
Key fields in the output:
Replicas: should be3 desired | 3 updated | 3 total | 3 available | 0 unavailableConditions: look forAvailablewith statusTrueEvents: look forScalingReplicaSetorSuccessfulCreate
A healthy example:
Name: web-deployment
Namespace: production
Selector: app=web
Labels: app=web
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=web
Containers:
web:
Image: nginx:1.25
Port: 80/TCP
Limits:
cpu: 600m
memory: 300Mi
Requests:
cpu: 200m
memory: 128Mi
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 10m deployment-controller Scaled up replica set web-deployment-xxxxx to 3
Check Actual Pod Resource Usage
Use kubectl top to see live resource consumption:
kubectl top pods -n production -l app=web
Example output:
NAME CPU(cores) MEMORY(bytes)
web-deployment-xxxxx 180m 120Mi
web-deployment-yyyyy 190m 125Mi
web-deployment-zzzzz 175m 118Mi
Compare these numbers to your requests and limits. In this case, usage is below requests, which is normal because requests are a guaranteed minimum, not a cap. If usage consistently exceeds requests, you should increase the request to improve scheduling accuracy. If usage approaches limits, you need to raise the limit or optimize the application.
Verify Endpoint Availability
If a Service fronts the Deployment, check that the endpoints include the pod IPs:
kubectl get endpoints -n production
Example:
NAME ENDPOINTS AGE
web-service 10.244.1.5:80,10.244.2.6:80,10.244.3.7:80 12m
You can also test the service from a temporary pod inside the cluster:
kubectl run curl-test --image=curlimages/curl -it --rm --restart=Never -- /bin/sh -c 'curl -s http://web-service.production.svc.cluster.local/'
This should return the default nginx page if the pod is serving correctly.
Simulate Load and Observe Behavior
A Deployment by itself does not autoscale; it only maintains the specified replica count unless you configure a HorizontalPodAutoscaler. To validate that 3 replicas can handle the expected traffic, you must generate load externally. Use a load testing tool such as hey or ab against the service endpoint. As you increase requests per second, monitor pod resource usage:
kubectl top pods -n production -l app=web
If CPU usage approaches the 600m limit, you may see throttling (visible as increased latency). If memory usage approaches 300Mi, pods may get OOMKilled. In either case, you need more replicas or higher limits.
You can also check the number of ready replicas programmatically:
kubectl get deployment web-deployment -n production -o jsonpath='{.status.readyReplicas}'
Expected output:
3
If readyReplicas is less than replicas, investigate pod readiness probes and any errors.
Common Pitfalls and How to Avoid Them
Capacity planning for Deployments often goes wrong in predictable ways. Here are the most frequent pitfalls, why they happen, and how to avoid or recover from each.
Pitfall 1: Setting Memory Requests Too Low
Why it happens: Teams look at average memory usage and set the request to that value, forgetting that Kubernetes uses requests for scheduling and for node pressure eviction decisions.
Consequence: When a node runs out of memory, the kubelet evicts pods based on their memory usage relative to request. A pod with a low request but high actual usage is more likely to be evicted, causing application downtime.
How to avoid: Set memory requests to a value closer to the expected steady-state usage under normal load, not the minimum. For our example, even though idle memory is 128Mi, if typical load uses 200Mi, set the request to 200Mi. Monitor kubectl top pods over several days to find the actual 95th percentile memory usage and use that as the request.
Pitfall 2: Not Defining CPU Limits
Why it happens: Some teams set CPU requests but omit CPU limits either out of caution (fear of throttling) or ignorance. However, without a limit, a single pod can consume all available CPU on a node, starving neighboring pods.
Consequence: A runaway process in one container can throttle all other pods on the same node, leading to cascading latency and timeouts.
How to avoid: Always set a CPU limit, even if it is generous. For our example, the limit is 600m, which is three times the request. If you never want an upper bound, set a very high limit, but be aware that CPU limits are enforced by throttling and may cause latency spikes for bursty workloads.
Pitfall 3: Forgetting that Deployments Do Not Autoscale by Default
Why it happens: Teams new to Kubernetes assume that a controller automatically scales pods based on load. Deployments maintain a fixed replica count unless you attach an autoscaler.
Consequence: When traffic increases, the application becomes overloaded because the number of pods remains static.
How to avoid: Monitor load and manually scale when needed using kubectl scale deployment web-deployment --replicas=5 -n production. For automatic scaling, configure a HorizontalPodAutoscaler that targets the Deployment. Do not rely on the Deployment alone to adjust replica count under load.
Pitfall 4: Overly Restrictive ResourceQuota
Why it happens: A quota is set without fully accounting for the total resource requests of all workloads in the namespace.
Consequence: When you try to scale up, pod creation fails with a forbidden: exceeded quota error. You may not notice until a deployment fails or a production incident reveals the bottleneck.
How to avoid: Calculate the total resource requests for all expected pods, add 20 to 30 percent headroom, and set the quota accordingly. Monitor quota utilization regularly with kubectl describe resourcequota.
Pitfall 5: Failing to Monitor a Rolling Update
Why it happens: You update the Deployment pod template to change resource limits or the container image, and assume that either nothing happens or that all pods update instantly. Deployments perform rolling updates according to the strategy field; old and new pods coexist temporarily.
Consequence: A bad resource change can cause the new pods to fail readiness checks, get OOMKilled, or crash. If you do not monitor the rollout, the Deployment may get stuck in a failed rollout or serve traffic with a mix of broken and healthy pods.
How to avoid: After applying a change, monitor the rollout status:
kubectl rollout status deployment web-deployment -n production
If the rollout does not progress, inspect events with kubectl describe deployment web-deployment -n production. To revert a bad change, use kubectl rollout undo deployment web-deployment -n production. Do not manually delete pods to force a change; the Deployment controller handles replacement.
Failure Modes and Recovery
Even with careful planning, failures happen. Here are four common failure modes related to capacity, how to detect them, and how to recover.
Failure Mode 1: Pod Evictions Due to Node Memory Pressure
What happens: A node runs out of memory, and the kubelet evicts pods to prevent the node from crashing. Evicted pods are recreated by the Deployment controller on another node if resources are available.
Detection: Check for evicted pods and node conditions:
kubectl get pods -n production --field-selector=status.reason=Evicted
kubectl describe node node-1 | grep -A5 Conditions
If you see MemoryPressure as True, the node is under stress. The Deployment controller will create replacement pods, but if the cluster is globally short on memory, they may go Pending.
Recovery:
- Scale down the Deployment to reduce memory demand:
kubectl scale deployment web-deployment --replicas=2 -n production
- Investigate whether your memory requests are too low. Increase them to reflect actual usage if needed, but be aware that this may require adding node capacity.
- Add more nodes or reduce memory usage of the application (e.g., by fixing memory leaks or optimizing caches).
Failure Mode 2: OOMKilled Pods in CrashLoopBackOff
What happens: A container exceeds its memory limit. The kernel kills the process with an OOM error. The pod restarts, and if it keeps exceeding the limit, it enters CrashLoopBackOff.
Detection: Inspect the pod's last state:
kubectl describe pod web-deployment-xxxxx -n production | grep -A5 'Last State'
Output shows Reason: OOMKilled. Also check memory usage:
kubectl top pods -n production -l app=web
If memory usage is near the limit (e.g., 290Mi out of 300Mi), you need to increase the limit.
Recovery:
- If the application legitimately needs more memory, increase the limit. Edit the Deployment and apply:
kubectl edit deployment web-deployment -n production
# change memory limit to 400Mi, save and exit
- The Deployment controller performs a rolling update and replaces pods automatically. Monitor the rollout:
kubectl rollout status deployment web-deployment -n production
- If the memory usage is due to a leak, debug and fix the application before simply raising limits, otherwise the problem will recur.
Failure Mode 3: Pending Pods Due to Insufficient Cluster Resources
What happens: You scale up the Deployment, but the new pods cannot be scheduled because no node has enough free CPU or memory to meet their requests.
Detection:
kubectl get pods -n production
You see several pods in Pending status. Describe one:
kubectl describe pod <pending-pod> -n production
The events section includes messages like:
0/3 nodes are available: 3 Insufficient cpu.
Recovery:
- Scale down to a sustainable replica count:
kubectl scale deployment web-deployment --replicas=2 -n production
- If the requests were overestimated, reduce them after re-evaluating actual usage.
- Add nodes to the cluster to increase capacity.
- Revisit your capacity model: you may need to plan for peak traffic more accurately.
Failure Mode 4: ResourceQuota Exceeded
What happens: The namespace ResourceQuota is exhausted, so new pods cannot be created even if cluster resources are available.
Detection: Check the Deployment events:
kubectl describe deployment web-deployment -n production
Look for events like:
Warning FailedCreate 2m (x5 over 10m) deployment-controller Error creating: pods 'web-deployment-xxxxx' is forbidden: exceeded quota: production-quota, requested: pods=1, used: pods=10, limited: pods=10
Recovery:
- Either increase the quota (if the new demand is legitimate):
kubectl edit resourcequota production-quota -n production
Change pods: '10' to a higher number, save, and exit.
- Or reduce the number of replicas to fit within the existing quota.
- Review whether the quota should be adjusted permanently or whether the scale-up was temporary.
Rollback Considerations
Always keep a known-good version of your Deployment manifest in version control. If a configuration change causes problems (for example, you set a CPU request so high that nothing can schedule), you can roll back by applying the previous manifest or using the rollout undo command.
Steps to rollback:
- Retrieve the previous manifest from your version control system (e.g.,
git checkout). - Apply it:
kubectl apply -f web-deployment.yaml
- If the pod template changed, the Deployment controller will perform a rolling update. To roll back to the previous revision quickly, use:
kubectl rollout undo deployment web-deployment -n production
This restores the Deployment to its previous state.
Operations Checklist
Use this checklist during capacity planning and ongoing operations. For each recurring item, assign a single owner to ensure accountability. In our example, the owner is the platform engineer on call.
| Task | Command / Check | Frequency | Owner |
|---|---|---|---|
| Review current replica count vs. desired | kubectl get deployments -n production | Daily during active changes | Platform engineer on call (e.g., Alex Rivera) |
| Check pod resource usage vs. requests/limits | kubectl top pods -n production -l app=web | Daily or when traffic changes | Application owner (e.g., Maria Chen) |
| Verify pod readiness and status | kubectl get pods -n production | Continuous monitoring | Monitoring system with alert |
| Check for evicted or OOMKilled pods | kubectl get pods -n production --field-selector=status.phase=Failed | Each incident | SRE on call (e.g., Jordan Patel) |
| Review Deployment events | kubectl describe deployment web-deployment -n production | After any scaling change | Platform engineer on call |
| Validate resource quota utilization | kubectl describe resourcequota production-quota -n production | Weekly | Platform engineer on call |
| Load test after significant traffic changes | Custom load test against service endpoint | Before major events (e.g., product launch) | Performance engineer (e.g., Sam Lee) |
| Review node capacity and utilization | kubectl top nodes | Weekly | Infrastructure team lead (e.g., Priya Shah) |
| Update resource requests/limits based on observed usage | Edit manifest and apply; Deployment will perform a rolling update | As needed (at least quarterly review) | Application owner with platform engineer approval |
Additional operating notes:
- Always have a rollback plan before changing resource settings or replica counts.
- Use version control for all Kubernetes manifests; never edit live manifests by hand without updating the source of truth.
- If you need automatic scaling, configure a HorizontalPodAutoscaler for the Deployment. The HPA works with Deployments via the scale subresource and is the standard approach.
- Monitor cluster-level metrics such as node CPU and memory utilization, not just pod-level metrics, to anticipate capacity shortages before they affect applications.
- Revisit capacity plans at least once per quarter or after any major traffic change (e.g., marketing campaign, new feature release).
Conclusion
Capacity planning for Kubernetes Deployments is an iterative process, not a one-time task. By following the steps in this guide, you can establish a baseline, set appropriate resource requests and limits, choose a safe initial replica count, and verify that your configuration works under load. We also covered common pitfalls and failure modes, along with concrete recovery commands and an operations checklist that assigns ownership and review cadence.
The key takeaways are:
- Measure your application's actual resource usage before setting requests and limits; never guess.
- Start with conservative estimates and scale up based on observed data and load tests.
- Use ResourceQuotas to prevent runaway resource consumption and enforce best practices.
- Monitor pod usage and node capacity regularly, and alert on evictions, OOMKills, and pending pods.
- Always keep a rollback plan and a versioned manifest for every change.
- Assign a single owner to each operational task and revisit your capacity plan quarterly or after major traffic changes.
Now apply these principles to your own Deployment-managed workloads. Adapt the example numbers to your application's specific behavior, and treat capacity planning as a continuous cycle of measure, adjust, and verify. With a disciplined approach, you can keep your services performant, reliable, and cost-effective.
---
The examples in this article are hypothetical and for illustration only. Always test configurations in a non-production environment before applying them to production clusters.