Summary - ReplicaSet
- Docker & Kubernetes course
- Intermediate
- Lesson 36/82
- 5 min
Combine YAML, selector and scale to manage a ReplicaSet.
Summary: ReplicaSet
In this group:
- A ReplicaSet keeps the number of pods matching its selector at
replicas; it does no version management. - It isn't used directly; a Deployment creates it, and old ReplicaSets are kept for rollback.
- It owns pods by label; a pod whose label changes is detached and a new one opens in its place.
- Scaling is done through the top owner (Deployment);
--current-replicasscales conditionally. - Self-healing: the kubelet restarts containers, the ReplicaSet recreates pods;
logs --previousshows the crashed one.
kubectl get rs -l app=web
kubectl label pod <pod> app=inceleme --overwrite
kubectl logs <pod> --previousPractice A ReplicaSet with matchExpressions
Write a ReplicaSet YAML: name api, replicas: 2; the selector uses matchExpressions with key: app, operator: In, values: [api]; template label app: api; container named api, image api:1.0.
Starter code
# buraya yazSample solution
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: api
spec:
replicas: 2
selector:
matchExpressions:
- key: app
operator: In
values: [api]
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: api:1.0Expected output
replicaset.apps/api created
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 When a ReplicaSet template's image changes, what happens to the existing pods?
- They are deleted
- They update gradually
- Nothing; only newly created ones get the new image Correct answer
- They are recreated immediately
Explanation: Rolling updates are the Deployment's job.
2 Show the pods with their labels.
kubectl get pods ____
kubectl get pods --show-labels
Explanation: --show-labels shows all labels in one column.
3 Match.
| Term | Meaning |
|---|---|
ReplicaSet |
Replica count |
Deployment |
Version transitions |
label |
Ownership criterion |
reconciliation loop |
Observe, compare, fix |