10.23 Kubernetes Workload Scaling Control
Kubernetes Workload Scaling Control manages container scaling, optimizing resource use and performance in dynamic environments.
Kubernetes Workload Scaling Control is the collection of mechanisms through which the number of running replicas for a workload is adjusted, whether through direct manual specification, automated horizontal scaling based on observed metrics, or automated vertical adjustment of resource allocations, allowing a workload's capacity to be matched to actual demand rather than fixed permanently at creation time.
Manual Scaling
Direct Replica Count Adjustment
The most straightforward form of scaling control involves directly modifying a workload's replicas field, whether on a Deployment, ReplicaSet, or StatefulSet, prompting the underlying controller to reconcile the actual Pod count toward this newly specified target through ordinary Pod creation or deletion.
Scale Subresource
Kubernetes exposes a dedicated scale subresource on scalable workload types, allowing scaling operations to be performed through a narrower, purpose-built API surface rather than requiring a full read-modify-write cycle against the entire workload object, which is particularly relevant for automated scaling systems that only need to adjust replica count.
Horizontal Pod Autoscaling
Metric-Driven Replica Adjustment
The HorizontalPodAutoscaler continuously monitors specified metrics, such as average CPU utilization or custom application-level metrics, across the Pods of a target workload, and automatically adjusts the replica count within a configured minimum and maximum range to maintain those metrics near a specified target value.
Scaling Behavior Configuration
The behavior field allows fine control over how aggressively the HorizontalPodAutoscaler scales up or down, including stabilization windows that prevent rapid oscillation in replica count in response to short-lived metric spikes, and explicit policies limiting how much or how quickly scaling can occur within a given time period.
Vertical Pod Autoscaling
Adjusting Resource Requests Rather Than Replica Count
Rather than changing how many Pods run, vertical scaling adjusts the CPU and memory requests and limits assigned to each Pod's containers, recommending or automatically applying values based on observed historical resource usage, which is particularly relevant for workloads where the appropriate per-Pod resource allocation is not known upfront or changes over time.
Update Modes
Vertical scaling mechanisms typically support different update modes, ranging from generating recommendations only, which require manual application, to automatically updating resource requests on newly created Pods, to actively evicting and recreating existing Pods to apply updated resource values immediately.
Interaction Between Scaling and Rollouts
Scaling During an Active Rollout
When a scaling operation occurs while a Deployment rollout is already in progress, the replica count adjustment is distributed proportionally between the old and new ReplicaSets involved in the rollout, ensuring the overall desired capacity is honored while the rollout continues progressing toward the updated template.
Autoscaler Awareness of Rollout State
A properly functioning HorizontalPodAutoscaler operates against the Deployment's overall desired replica count rather than any individual ReplicaSet, meaning its scaling decisions remain coherent and continuous even as the underlying ReplicaSet composition shifts during an ongoing rollout.
Constraints on Scaling
Resource Quota Limits
Namespace-level resource quotas can constrain how far a workload is able to scale, since Pod creation attempts that would exceed a namespace's configured quota for CPU, memory, or object count are rejected, meaning scaling operations must be considered alongside any quota boundaries in effect.
Cluster Capacity Boundaries
Beyond quota-based limits, the physical or provisioned capacity of the underlying cluster itself constrains scaling, since even a workload permitted by quota to scale further cannot actually do so if no nodes have sufficient allocatable resources to host the additional Pods, absent a cluster autoscaler capable of provisioning new node capacity.