Managing Containers at Scale
What changes when one service becomes hundreds: requests, autoscaling layers, guardrails, GitOps, fleets of clusters, observability and cost.
Running one container in the cloud is a solved problem; the previous article did it on three providers in an afternoon. Running three hundred services for ten teams across several clusters is a different job. The individual commands barely change. What changes is that nothing can depend on someone remembering to do the right thing by hand.
This article closes the Container Services series by looking at that second job. It focuses on Kubernetes, because that is where most large container estates end up, but the same ideas apply to ECS, Cloud Run and Container Apps in smaller form.
What actually changes at scale
Scale shows up along three axes, and each brings its own problems:
- More workloads. Capacity planning by hand stops working. Bad resource settings on one service waste money or starve its neighbours.
- More people. Teams share clusters, so you need boundaries: who can deploy where, how much each team can use, and which settings are not optional.
- More clusters. Regions, environments and compliance boundaries multiply clusters. Upgrades, policy and configuration have to be applied to all of them consistently.
The answer to all three is the same shape: describe the desired state in files, let controllers enforce it, and measure the result. The rest of this article is the concrete version of that.
flowchart LR
G["Git: manifests and policy"] --> R["GitOps controller"]
R --> C1["Cluster: dev"]
R --> C2["Cluster: staging"]
R --> C3["Cluster: prod"]
P["Admission policy"] -.-> C1
P -.-> C2
P -.-> C3
C1 --> O["Metrics, logs, traces"]
C2 --> O
C3 --> O
O --> F["Dashboards, alerts, cost reports"]
Resource requests are the foundation
Every scaling and cost decision in Kubernetes starts from resource requests. The scheduler places a pod on a node only if the node has enough unrequested CPU and memory. The cluster autoscaler and Karpenter add nodes when pending pods’ requests don’t fit. GKE Autopilot bills you by them. If requests are wrong, everything built on top is wrong too.
Two failure modes are common:
- Requests too low. Pods get packed onto nodes that can’t sustain them. Under load, memory runs out and the kernel kills containers, or CPU contention slows everything on the node.
- Requests too high. Nodes look full while actually sitting mostly idle. You pay for capacity nobody uses, and in a shared cluster one team’s padding blocks another team’s pods.
Limits are a separate setting. A memory limit is a hard ceiling: exceed it and the container is killed. A CPU limit throttles the container even when the node has spare CPU, which is why many teams set memory limits equal to memory requests and leave CPU limits off for latency-sensitive services. Whatever you choose, choose it deliberately and make it the default.
Right-sizing with the Vertical Pod Autoscaler
You rarely know good requests up front. The Vertical Pod Autoscaler (VPA) watches actual usage and recommends requests for each container. Start in recommendation-only mode, which changes nothing and lets you read the numbers:
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: api
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: api
updatePolicy:
updateMode: "Off"
kubectl describe vpa api
The recommendation section shows a lower bound, a target and an upper bound per container. Copy the target into the Deployment, or let VPA apply it.
Applying used to mean evicting and recreating pods, which made people nervous about turning it on. In-place pod resize, stable since Kubernetes 1.35, lets the kubelet change a running container’s CPU and memory, often without a restart. VPA’s InPlaceOrRecreate update mode uses it, falling back to recreation when an in-place change isn’t possible; that mode is still beta in VPA, so check its status in your VPA version before relying on it.
One rule matters more than the details: don’t let VPA and the Horizontal Pod Autoscaler both act on the same CPU or memory signal for the same workload. They will fight, one shrinking requests while the other adds replicas based on utilization of those requests.
A cluster shows nodes at 90 percent requested CPU, but measured CPU usage sits around 15 percent. The node autoscaler keeps adding nodes. What is the most likely cause?
Correct! Scheduling and node autoscaling work from requests, not usage, so inflated requests make nodes look full and trigger new ones while real usage stays low.
The layers of autoscaling
Autoscaling in Kubernetes is not one feature. It is a stack of controllers, each answering a different question, and they only work well together if each layer has sensible inputs.
flowchart TB
T["Traffic or queue depth"] --> H["HPA or KEDA: how many replicas?"]
H --> V["VPA: how big is each replica?"]
V --> S["Scheduler: which node?"]
S -->|"pods pending"| N["Cluster autoscaler or Karpenter: add nodes"]
N --> S
S -->|"nodes underused"| D["Consolidation: drain and remove nodes"]
Horizontal scaling on metrics
The Horizontal Pod Autoscaler (HPA) changes the replica count of a Deployment to keep a metric near a target. CPU utilization is the default, measured against requests, which is one more reason requests need to be right. The behavior section controls how fast it reacts, and it is worth setting at scale so a brief spike doesn’t double your fleet and a brief lull doesn’t halve it:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: api
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api
minReplicas: 3
maxReplicas: 40
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 65
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 20
periodSeconds: 60
Event-driven scaling with KEDA
CPU is a poor signal for queue workers. A worker waiting on an empty queue uses no CPU, and a worker falling behind may not use much either. KEDA, a graduated CNCF project, scales on the thing that actually matters: queue length, stream lag, a Prometheus query or a cron schedule. It feeds those metrics to an HPA it manages, and it can scale a workload to zero replicas when there is nothing to do.
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: orders-worker
spec:
scaleTargetRef:
name: orders-worker
minReplicaCount: 0
maxReplicaCount: 50
triggers:
- type: aws-sqs-queue
authenticationRef:
name: keda-aws
metadata:
queueURL: https://sqs.us-east-1.amazonaws.com/123456789012/orders
queueLength: "20"
awsRegion: us-east-1
Here KEDA targets about 20 messages per replica. Azure Container Apps uses KEDA internally, as the orchestration comparison described, and AKS offers it as a managed add-on.
Node scaling
Pod autoscalers create pods; something has to create machines for them. There are two models:
- Cluster autoscaler. Scales predefined node groups up when pods are pending and down when nodes are underused. Predictable, but you have to choose instance types per group in advance.
- Karpenter-style provisioning. Looks at pending pods directly and launches whatever instance size and type fits them, then consolidates by moving pods and removing nodes that are no longer needed. EKS Auto Mode and AKS node auto-provisioning are built on Karpenter; GKE’s equivalent is node auto-provisioning on Standard and fully managed capacity on Autopilot.
At scale the second model usually wins, because it can mix sizes, prefer Spot capacity and pack nodes more tightly than fixed groups. The trade-off is that it moves pods around more often, which makes the next section essential.
Keeping workloads available while everything moves
In a large cluster, pods are evicted all the time: consolidation, node upgrades, Spot reclamation, VPA updates. None of that should cause an outage. Four settings do most of the work.
| Setting | What it protects against | Typical choice |
|---|---|---|
| Readiness probe | Traffic reaching a pod before it can serve | An HTTP check on a cheap endpoint |
| PodDisruptionBudget | Voluntary evictions taking down too many replicas at once | maxUnavailable: 1 or a percentage |
| Topology spread constraints | All replicas landing in one zone or on one node | Spread across topology.kubernetes.io/zone |
| PriorityClass | Batch jobs pushing out critical services when capacity is short | A high class for user-facing services |
A PodDisruptionBudget tells the cluster how many replicas it may take away voluntarily. Node drains, Karpenter consolidation and managed upgrades all respect it:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: api
spec:
maxUnavailable: 1
selector:
matchLabels:
app: api
Spreading across zones goes in the pod template:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: api
Be careful with budgets that allow zero disruptions, such as maxUnavailable: 0 on a single-replica Deployment. They block node drains indefinitely, which stalls upgrades and consolidation for the whole node. Zones themselves are covered in the regions and availability zones guides for AWS and Azure.
A managed node upgrade has been stuck for hours on one node. That node runs the only replica of a Deployment whose PodDisruptionBudget sets minAvailable to 1. What is happening?
Correct! With one replica and minAvailable 1, no voluntary eviction is ever permitted, so run at least two replicas or allow one to be unavailable.
Sharing clusters between teams
Most organizations run fewer, larger clusters shared by several teams, because each cluster carries fixed cost and operational overhead. Sharing safely needs boundaries at a few levels.
Namespaces are the unit of ownership. Give each team or service its own, and attach everything else to them.
RBAC decides who can do what in each namespace. Bind cloud identities (IAM roles, Google groups, Entra ID groups) to Kubernetes roles rather than issuing static credentials; the IAM guides for AWS, GCP and Azure cover the cloud side.
ResourceQuota and LimitRange cap what a namespace can consume and fill in defaults for pods that forget to set requests:
apiVersion: v1
kind: ResourceQuota
metadata:
name: team-payments
namespace: payments
spec:
hard:
requests.cpu: "40"
requests.memory: 80Gi
pods: "200"
---
apiVersion: v1
kind: LimitRange
metadata:
name: defaults
namespace: payments
spec:
limits:
- type: Container
defaultRequest:
cpu: 100m
memory: 128Mi
default:
memory: 256Mi
NetworkPolicy restricts which pods can talk to which. Without it, every pod can reach every other pod in the cluster. A default-deny policy per namespace, plus explicit allows, turns the network into something you can reason about. Policies only take effect if the cluster’s network plugin enforces them, so confirm that on your provider.
Guardrails as code
Quotas and RBAC limit how much and who. Admission policy limits what. It rejects manifests that break rules before they reach the cluster: containers without requests, images from untrusted registries, privileged pods, missing ownership labels.
Kubernetes has a built-in option, ValidatingAdmissionPolicy, stable since 1.30, which expresses rules in CEL and runs inside the API server with no extra webhook to operate:
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: require-requests
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: ["apps"]
apiVersions: ["v1"]
operations: ["CREATE", "UPDATE"]
resources: ["deployments"]
validations:
- expression: >-
object.spec.template.spec.containers.all(c,
has(c.resources) && has(c.resources.requests) &&
'cpu' in c.resources.requests &&
'memory' in c.resources.requests)
message: "Every container must set CPU and memory requests."
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: require-requests
spec:
policyName: require-requests
validationActions: ["Deny"]
matchResources:
namespaceSelector:
matchLabels:
tenancy: shared
For richer needs, such as mutating resources, generating defaults or a library of ready-made rules, teams use Kyverno or OPA Gatekeeper. GKE packages Gatekeeper as Policy Controller, and Azure Policy for AKS is built on Gatekeeper too. Roll new policies out in audit or warn mode first (validationActions: ["Audit"] or ["Warn"] above), read what they would have blocked, then switch to deny.
Deploying with GitOps
At a handful of services, a CI job running kubectl apply is fine. At hundreds, you lose track of what is actually running and who changed it. GitOps fixes that by making a Git repository the source of truth and running a controller in or next to each cluster that continuously pulls the repository and reconciles the cluster to match.
sequenceDiagram
participant Dev as Developer
participant Git as Git repository
participant CI as CI pipeline
participant Reg as Image registry
participant Ctl as GitOps controller
participant K as Cluster
Dev->>Git: Merge app change
Git->>CI: Trigger build
CI->>Reg: Push image tagged with commit
CI->>Git: Update image tag in manifests
Ctl->>Git: Poll or receive webhook
Ctl->>K: Apply the difference
Ctl->>K: Revert any manual drift
The benefits are practical. Every change is a reviewed commit. Rollback is git revert. Drift from someone running kubectl edit in production gets corrected automatically. CI no longer needs credentials to every cluster, because the controller pulls rather than CI pushing.
The two common controllers are Argo CD and Flux, both graduated CNCF projects. Each cloud now offers a managed route:
- AWS: the EKS Capability for Argo CD runs Argo CD in AWS-managed infrastructure rather than on your nodes, and one instance can deploy to several EKS clusters.
- Google Cloud: Config Sync syncs from Git, OCI images or Helm repositories to clusters registered in a fleet.
- Azure: the GitOps extension for AKS and Arc-enabled clusters installs and manages Flux.
Structure the repository so that environment differences are small overlays on a shared base, using Kustomize or Helm values per environment. If staging and production manifests are separate copies, they will drift apart in ways nobody notices until an incident.
During an incident, an engineer scales a production Deployment from 4 to 12 replicas with kubectl. Ten minutes later it is back at 4. The cluster uses Argo CD with self-heal enabled and no autoscaler. Why?
Correct! With self-heal on, Git is the desired state, so the change has to be made in the repository, or the replica count left to an autoscaler.
Managing fleets of clusters
Eventually one cluster per environment becomes one per region per environment, and sometimes one per team. Treating each cluster as a pet stops working long before you reach dozens. Cluster creation should be code (Terraform, Pulumi, CloudFormation or Bicep), and the clusters should be managed as a group. The providers approach the group differently.
| AWS | Google Cloud | Azure | |
|---|---|---|---|
| Grouping concept | No single fleet object; organize by accounts and tags | Fleets of registered clusters | Azure Kubernetes Fleet Manager |
| Config and app delivery | EKS Capability for Argo CD across clusters | Config Sync per fleet | Fleet resource placement, or Flux via the GitOps extension |
| Policy across clusters | Kyverno or Gatekeeper, delivered by GitOps | Policy Controller | Azure Policy for AKS |
| Coordinated upgrades | Your own pipeline, cluster by cluster | Rollout sequencing with soak times between groups | Update runs with stages, groups and maintenance windows |
| Multi-cluster traffic | Load balancers and Route 53 in front of clusters | Multi-cluster Gateway | Fleet multi-cluster networking or Front Door |
Coordinated upgrades deserve the most attention. Kubernetes releases minor versions about three times a year and each is supported for a limited period, so a fleet is always mid-upgrade somewhere. GKE rollout sequencing upgrades groups of clusters in order, such as development then production, and waits a soak time between them. Fleet Manager update runs do the same for AKS in sequential stages and respect each cluster’s maintenance window; if you use them, disable auto-upgrade on the member clusters so the two mechanisms don’t compete. On EKS you build the sequence yourself, typically as a pipeline that upgrades one cluster, runs checks and moves to the next.
Before any upgrade, check for deprecated APIs in your manifests. Tools such as kubent or pluto scan for them, and upgrade insights in the EKS, GKE and AKS consoles flag clusters that are still calling removed APIs.
Observability that keeps up
With hundreds of services, you can’t watch dashboards per pod. You need a small set of signals per service, collected the same way everywhere.
- Metrics. Prometheus is the standard format. Each cloud runs a managed, Prometheus-compatible backend: Amazon Managed Service for Prometheus, Google Cloud Managed Service for Prometheus and Azure Monitor managed service for Prometheus. Track request rate, errors and latency per service, and saturation per node.
- Logs. Write structured JSON to stdout and let the platform collect it. Centralize retention rules; log volume is one of the easiest bills to lose control of.
- Traces. Instrument with OpenTelemetry so services can switch backends without code changes, and propagate trace context between services.
Alert on symptoms users feel, such as error rate and latency against a service level objective, rather than on every pod restart. At scale, something is always restarting.
Keeping cost under control
Container cost grows quietly because nobody sees the bill per service. Three habits help.
Make cost visible per team. GKE cost allocation adds namespace and label breakdowns to the Cloud Billing export. AWS split cost allocation data assigns EC2 cost to EKS and ECS workloads. The AKS cost analysis add-on breaks cluster cost down by namespace and other Kubernetes constructs. Consistent labels for team and service make all three useful.
Pack nodes tightly. Right-sized requests, Karpenter-style consolidation and a mix of instance sizes raise utilization. Low-requested, high-usage pods are the exception to chase; high-requested, low-usage pods are the money.
Use cheaper capacity where it fits. Stateless, replicated services and batch jobs tolerate Spot or preemptible nodes well, especially with PodDisruptionBudgets and zone spreading in place. Steady baseline capacity is a candidate for commitments. Pricing Models: On-Demand, Reserved, Savings Plans, and Spot explains the trade-offs.
Finally, keep asking whether a workload needs Kubernetes at all. A service with spiky HTTP traffic and no special requirements is often cheaper and simpler on Cloud Run, Container Apps or ECS on Fargate, as the orchestration comparison argued.
Further reading
- Kubernetes: resource management for pods and containers
- Kubernetes: horizontal pod autoscaling
- Kubernetes: ValidatingAdmissionPolicy
- KEDA documentation
- Amazon EKS Capability for Argo CD
- GKE rollout sequencing
- Azure Kubernetes Fleet Manager overview
Key takeaways
- At scale, the work shifts from running containers to enforcing desired state automatically: files in Git, controllers that apply them, and measurements that show the result.
- Resource requests drive scheduling, node autoscaling and often billing. Measure real usage with VPA and keep requests honest.
- Autoscaling is layered: HPA or KEDA for replica count, VPA for replica size, and the cluster autoscaler or Karpenter for nodes. Don’t let HPA and VPA act on the same signal.
- PodDisruptionBudgets, readiness probes, zone spreading and priority classes keep services up while nodes are constantly replaced.
- Shared clusters need namespaces, RBAC, quotas, network policy and admission policy. Roll policies out in audit mode before enforcing them.
- GitOps with Argo CD or Flux gives you reviewed changes, easy rollback and automatic drift correction across many clusters.
- Manage clusters as a fleet, with coordinated upgrades and consistent policy, and make cost visible per team so it can be owned.
Part 7 of 7 · Container Services