In Chapter 1 you met Pods that came back. The object that brought them back was a ReplicaSet.
Three things
A ReplicaSet needs three things:
1. How many Podsreplicas: 3
2. How to recognise its Podsselector.matchLabels
3. How to make a new onetemplate: a Pod manifest
yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27The template is a Pod manifest with the apiVersion and kind left off. The selector must match the template's labels, or the API server refuses the object:
text
The ReplicaSet "web" is invalid: spec.template.metadata.labels: Invalid value: ... `selector` does not match template `labels`What it does
text
learner@shallows:~$ kubectl get rs
NAME DESIRED CURRENT READY AGE
web 3 3 3 20s
learner@shallows:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
web-7f4kq 1/1 Running 0 20s
web-m2q8n 1/1 Running 0 20s
web-x7k2p 1/1 Running 0 20sPods get the ReplicaSet's name plus a random suffix. Delete one and the count drops to 2; the ReplicaSet makes a third, with a new suffix. Scale it and it makes or removes Pods until the count matches:
text
learner@shallows:~$ kubectl scale rs web --replicas=5
replicaset.apps/web scaledYou will rarely write a ReplicaSet yourself. The next lesson shows the object that writes them for you.