liveBook · Manning

Scalability

As explained in Kubernetes for Developers

Scaling is the adjustment of application instances or computing capacity to match changing workload demand.

When traffic rises, an application needs more capacity to serve users; when traffic falls, excess capacity costs money. Scalability means being able to adjust that capacity without waiting for someone to intervene during every spike. section 6.0

In Kubernetes, two kinds of capacity must grow together:

  • Pods run copies of the application. Increase replicas to serve more traffic, either by changing a Deployment’s replicas field or by using kubectl scale. section 6.1
  • Nodes provide the compute resources those Pods need. More Pods without room to run may remain Pending; more nodes without Pods provide only empty capacity. section 6.1

Adding replicas is horizontal scaling; giving each replica more resources is vertical scaling. A Horizontal Pod Autoscaler (HPA) can add or remove replicas against a target metric, within configured minimum and maximum counts. For a CPU target, it compares average utilization across Pods with the target, using their CPU resource requests. Cooldown periods limit repeated changes. Cluster autoscaling can add nodes when the provider supports it, completing the other side of the capacity adjustment. section 6.2 section 6.5

Listing 6.2 Chapter06/6.2_HPA/hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: timeserver
spec:
  minReplicas: 1                 #1
  maxReplicas: 10                #2
  metrics:
  - resource:
      name: cpu
      target:
        averageUtilization: 20   #3
        type: Utilization
    type: Resource
  scaleTargetRef:                #4
    apiVersion: apps/v1          #4
    kind: Deployment             #4
    name: timeserver             #4

This HPA configuration targets a Deployment, sets a 20% average CPU-utilization target, and bounds scaling between one and ten replicas. section 6.2

Test a traffic spike

Add a CPU-intensive /pi endpoint, generate requests with Apache Bench, then watch CPU use and replica counts with kubectl. If requested Pods stay Pending, check whether the cluster has enough node capacity rather than assuming the HPA failed. section 6.2 section 6.1

Plan for horizontal scaling while building the application, not after an unexpected surge. Where parts of an application need different amounts of capacity, microservices or multiple deployments can provide separate scaling groups. Placeholder Pods can also provide capacity headroom while autoscaling responds. section 6.4 section 6.5

How Kubernetes for Developers covers it

How deep it goes
Explains separate Pod and node scaling, HPA targets and limits, and a load test without detailing autoscaler internals.
Examples
Uses a Deployment replica setting, a CPU-targeted HPA manifest, and an Apache Bench load test against a CPU-intensive endpoint.
What it assumes
Starts from a deployed application with health checks; explains Pod and node scaling while relying on CPU resource requests for the HPA.
What you can do after
Operate/configure it with Deployment replicas and an HPA, then inspect Pods for unmet node capacity.
How it connects
Connects horizontal scaling to Deployments, resource requests, Horizontal Pod Autoscalers, cluster autoscaling, and microservices.

Also explained in

Compare how 27 books explain scalability →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.