ReplicaSets and Deployments
Keep three copies of a catalog running
A ReplicaSet maintains a target number of active Pods using a selector and a Pod template. A Deployment adds release management above that layer. Imagine three interchangeable catalog workers. If one Pod disappears, the ReplicaSet attempts to restore the missing copy. All examples are offline teaching material. The image registry and versions are deliberately non-deployable placeholders. No cluster, image or kubeconfig is included. Commands are static illustrations for a separately approved disposable cluster with verified ./lab.kubeconfig, bytemind-lab context, book-lab namespace, permissions and reviewed pinned images. Never run these against an unknown context.
Deployment catalog └─ ReplicaSet catalog-a ├─ Pod catalog-a-1 ├─ Pod catalog-a-2 └─ Pod catalog-a-3These are fictional names. Kubernetes assigns actual names and UIDs; a Deployment owns its ReplicaSets, and a ReplicaSet owns its Pods.
Read a Deployment manifest
The apps/v1 Deployment declares a desired replica count, selection rule and the template used for its Pods. The selector must agree with the template labels. Keep selectors specific so separate workloads do not overlap. The resource settings below are bounded illustrative CPU and memory values, not capacity recommendations.
apiVersion: apps/v1kind: Deploymentmetadata: name: catalog namespace: book-labspec: replicas: 3 selector: matchLabels: app: catalog template: metadata: labels: app: catalog spec: containers: - name: catalog image: registry.example.invalid/learning/catalog:1 resources: requests: cpu: 50m memory: 32Mi limits: cpu: 100m memory: 64MiThe outer metadata names the Deployment. The nested metadata labels its Pods. The nested spec describes the container. Saving the file does not create resources; a permitted API request would be needed. The image is intentionally invalid for execution.
Predict reconciliation without confusing readiness
Consider three active Pods, two of which report ready. The replica count is already satisfied, so readiness alone is not a request for another Pod. If an active Pod is removed, the controller attempts to create a replacement. A replacement can remain unscheduled, fail to fetch an image or fail to become ready. A controller is not a guarantee of application availability.
The first row has a missing active replica. The second row has enough active Pods but one is not ready. The third is healthy by this narrow count check, not necessarily by application behavior.
Inspect the controller hierarchy
Use the Deployment for ordinary workload management; avoid directly editing its owned ReplicaSets because the Deployment can reconcile them again. A standalone ReplicaSet lacks Deployment rollout management. A selector is not proof of ownership: a matching unowned Pod may be adopted, so check owner references and UIDs. The apps/v1 Deployment selector cannot be changed in place.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab get deployment/catalogkubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab get replicasets -l app=catalogkubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab get pods -l app=catalogThe lists are a starting point. Inspect owner references before deciding which objects belong to catalog. Commands require the approved lab and contact the API.
Practice: choose the controller action
Open lab-fixtures/deployments/replica-cases.json. For each fixed snapshot decide whether to create, remove or leave the active count unchanged. Explain why readiness can lag. Then read the catalog manifest and identify the selector and template. Next you will replace an application version without changing the workload identity.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
ReplicaSets and Deployments — knowledge check
Apply the lesson concepts to original offline scenarios.
A ReplicaSet wants three active Pods and has two. What does it attempt?
Three active Pods exist but one is unready. What follows from the count alone?
Which object directly owns ordinary Deployment-managed Pods?
Which field must agree with the Deployment selector?
What does a replacement Pod guarantee?