Scaling is not about adding pods fast. It is about adding the right pods, at the right time, without breaking what already works. I have owned Kubernetes end to end, from Terraform-driven clusters to GitOps deploys with Helm and Argo CD. The same problems kept showing up: wrong probes, missing requests, aggressive rollouts, and HPA chasing its own tail.
Probes: liveness, readiness, startup
Kubernetes needs three answers about a pod. Is it alive? Is it ready for traffic? Has it finished starting? Each question gets its own probe.
Liveness asks if the process is stuck. If it fails, Kubernetes restarts the container. Use it for deadlocks and hung threads, not to check a database or a downstream service. If the database is slow, you do not want every pod restarting at once.
Readiness asks if the pod can take traffic. If it fails, Kubernetes pulls the pod out of the Service. The pod keeps running, but it stops getting new requests. This probe protects users during deploys and partial outages.
Startup asks if the app has finished booting. It is for slow starts. A Spring microservice can take a while to warm up, and without a startup probe, liveness can kill the pod before it gets a chance to start.
startupProbe: httpGet: {path: /health/startup, port: 8080} failureThreshold: 30 periodSeconds: 10 livenessProbe: httpGet: {path: /health/live, port: 8080} periodSeconds: 10 failureThreshold: 3 readinessProbe: httpGet: {path: /health/ready, port: 8080} periodSeconds: 5 failureThreshold: 3 Keep endpoints light. Liveness should answer fast and touch little. Do not call downstream services from a readiness probe. That turns a small outage into a full outage.
Requests and limits: the basis for scaling
HPA cannot scale well if requests are wrong. Requests tell the scheduler how much CPU and memory a pod needs. Limits cap how much it can use. HPA uses requests to work out utilization.
If CPU requests are too low, pods look busy at low real load, and HPA adds pods too early. If requests are too high, pods look idle, and HPA adds pods too late.
Start with real data. Look at CPU and memory use over a normal week, plus peak hours. Set requests near typical use, not the peak. Set limits to protect the node. A pod that leaks memory can take a node down. Too tight a CPU limit will make latency spike under load.
resources: requests: {memory: "512Mi", cpu: "500m"} limits: {memory: "1Gi", cpu: "1000m"} This says the pod normally needs half a core and 512 Mi of memory, and it can burst to one core and 1 Gi. Tune it from metrics, not from a guess. Do not skip requests. A pod with no requests breaks HPA math.
HPA: CPU, memory, and custom metrics
The HorizontalPodAutoscaler adds or removes pods based on metrics. CPU is the most common trigger. Memory works too, but use it with care. Memory does not drop when load drops in the same way CPU does, so scaling on memory can keep extra pods around longer than you need.
apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: {name: api} spec: scaleTargetRef: {apiVersion: apps/v1, kind: Deployment, name: api} minReplicas: 3 maxReplicas: 20 metrics: - type: Resource resource: name: cpu target: {type: Utilization, averageUtilization: 70} This keeps average CPU use near 70 percent of requests. Set minReplicas to at least 2 or 3 for any service that matters. One pod is a single point of failure.
Custom metrics are where HPA gets useful. CPU is a proxy for load. Queue depth is load. Requests per second is load. If you run a worker that drains a queue, scale on queue depth, not CPU. If you run an API, scale on requests per second per pod.
You need a metrics pipeline for this. Prometheus with the adapter is a common path. Set a clear target per pod, like 100 requests per second per pod. Test the target under real load. A target that is too low will scale too fast. A target that is too high will scale too late. Set maxReplicas to what the rest of the system can handle.
Safe rollouts: maxSurge and maxUnavailable
A rollout replaces old pods with new pods. Two settings control the pace. maxSurge is how many extra pods can exist above the desired count. maxUnavailable is how many pods can be down at once.
A safe default is maxSurge 1 and maxUnavailable 1. With 6 replicas, this keeps at least 5 pods up at all times. It adds 1 new pod, waits for it to become ready, then removes 1 old pod. For a small service with 3 replicas, maxSurge 1 and maxUnavailable 0 is even safer.
For a fast rollout, you can raise maxSurge. That adds new pods quickly, but it costs more because you run extra pods. Do not raise maxUnavailable unless you can take the hit. Check the math for your replica count.
With Helm and Argo CD, rollout settings live in the chart. The same chart promotes the same build across environments, so the pace is tested in staging first. Fix it in the chart, not by hand in the cluster. Also set a progress deadline, so a stuck rollout fails loud.
PodDisruptionBudgets: protect the minimum
A PodDisruptionBudget, or PDB, sets how many pods must stay up during voluntary disruptions like node drains, cluster upgrades, and manual evictions. It does not stop all disruptions. It stops too many at once.
apiVersion: policy/v1 kind: PodDisruptionBudget metadata: {name: api} spec: minAvailable: 2 selector: {matchLabels: {app: api}} This says at least 2 pods with the label app api must stay available. If you have 3 replicas, only 1 can be drained at a time. Use minAvailable for small services, maxUnavailable for larger ones. Pick one, not both.
Test PDBs before an upgrade by draining a node in a test cluster. If the drain blocks, the PDB is doing its job. A PDB on a 1-replica Deployment will block drains, so add replicas instead of removing the PDB.
Anti-affinity: spread pods across nodes and zones
If all your pods land on one node, one node failure takes the service down. Anti-affinity spreads pods out, telling the scheduler to avoid placing pods with the same label on the same node or zone.
A soft rule is often enough. Use topologyKey kubernetes.io/hostname to spread across nodes, and topologyKey topology.kubernetes.io/zone to spread across zones. For a 3-replica service, zone spread across 3 zones is ideal.
This prefers a different node for each api pod. It is a preference, not a hard rule. If the cluster is full, the scheduler can still place two pods together. Hard anti-affinity can block scheduling when the cluster is tight, so use it only when you must guarantee separation.
When HPA flaps
Flapping is when HPA adds pods, then removes them, then adds them again. It wastes resources and makes latency jumpy.
First, check requests. If requests are too low, small load changes look like big utilization swings. Fix the requests first. HPA math depends on them.
Second, check the metric. CPU can spike for a few seconds and then drop. If HPA reacts to every spike, it will flap. Use a longer stabilization window. A scaleDown window of 5 minutes is a sane start. A bursty API needs a longer scaleDown window.
Third, check readiness. If new pods take a long time to become ready, HPA may add more pods while it waits. Fix the startup time or the startup probe, not maxReplicas.
Fourth, look for a bad custom metric. If the metric is noisy, HPA will be noisy. Smooth it at the source with an average over a minute.
Fifth, check minReplicas. If minReplicas is 1 and load is spiky, HPA will bounce between 1 and 3 all day. Raise the minimum to cover the normal base load. Let HPA handle the peaks, not the baseline. Flapping is a symptom. Fix the cause, usually bad requests, a noisy metric, or a short scaleDown window.
What I run in practice
I keep the same pattern across AKS and GKE. Terraform builds the cluster. Helm charts hold the Deployment, Service, HPA, and PDB. Argo CD syncs the chart to each environment. CI/CD promotes the same build from dev to staging to production. Only replica counts and resource values change.
Spring microservices on Google Cloud run on Cloud Run for small services and GKE for larger ones. The probe and HPA patterns are the same in both places. Keep manifests portable, with standard probes, HPA, and PDBs. Put cloud-specific settings in the environment values. That keeps the same app working on Azure, AWS, and GCP without a rewrite.
Checklist: scaling and staying up
- Liveness checks for stuck processes only, not downstream services.
- Readiness gates traffic, startup gates the boot phase.
- Requests set near typical use, limits set to protect nodes.
- HPA minReplicas at least 2 or 3 for services that matter.
- HPA maxReplicas set to what downstream systems can take.
- Custom metrics used where CPU is a poor proxy, like queue depth.
- Rollouts use maxSurge 1 and maxUnavailable 1 as a safe start.
- PDBs set so drains never take the service below its floor.
- Soft anti-affinity spreads pods across nodes and zones.
- ScaleDown stabilization set to avoid flapping after brief dips.
- Rollout and HPA settings live in Git, not typed by hand.
Next in the series: Managed Kubernetes Compared: AKS vs EKS vs GKE. I will compare what each managed service handles for you, where the defaults differ, and how to pick one without locking your app to it.

