liveBook · Manning

Replica count

As explained in Kubernetes in Action, Second Edition

A desired replica count is the configured number of pod replicas that a workload resource should maintain.

A replica count is the desired number of pod copies that a workload should maintain. In a ReplicaSet, Kubernetes creates that many pods from the Pod template and works to retain the same number. section 14.1.1

Declaring five replicas

A ReplicaSet manifest can set `spec.replicas` to `5`. Applying it creates five pods from the template. If matching pods already exist, the ReplicaSet can adopt them and create only the additional pods needed to reach five. section 14.1.1 section 14.1.2

Table 14.1 The main fields in the ReplicaSet specification
Field name
Description
replicas
The desired number of replicas. When you create the ReplicaSet object, Kubernetes creates this number of pods from the Pod template. The same number of pods is retained until you delete the ReplicaSet.
selector
The label selector contains either a map of labels in the matchLabels subfield or a list of label selector requirements in the matchExpressions subfield. Pods that match the label selector are considered part of this ReplicaSet.
template
The Pod template for the ReplicaSet’s pods. When a new pod needs to be created, the object is created using this template.

Use the ReplicaSet specification table to distinguish the replica count from the selector that identifies managed pods and the template that creates them. section 14.1.1

Inspect and change the desired count with kubectl:

  • `kubectl get rs kiada` displays desired, current, and ready replica counts, allowing the configured target to be compared with observed status. section 14.1.2
  • Change a ReplicaSet's count to scale it. For example, `kubectl scale rs kiada --replicas 7` raises the desired count. section 14.2 section 15.1.2
  • For a Deployment, change the Deployment's `replicas` field or run `kubectl scale deploy kiada --replicas 5`; its controller scales the underlying ReplicaSet. section 15.1.2
  • Avoid scaling a ReplicaSet owned by a Deployment directly: the Deployment controller can restore its count to the Deployment's configured value. section 15.1.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains declaration, status inspection, scaling, adoption, and controller reconciliation, but does not detail controller implementation internals.
Examples
Uses a five-pod Kiada ReplicaSet, kubectl status output, manifest editing, and kubectl scale commands.
What it assumes
Assumes basic Pods, manifests, kubectl, ReplicaSets, Deployments, label selectors, and Pod templates.
What you can do after
Operate scaling by declaring, inspecting, and changing replica counts with manifests and kubectl.
How it connects
Connects replica count with ReplicaSet, Deployment, Pod template, label selector, readiness probes, and controllers.

Also explained in

Compare how 2 books explain replica count →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.