ReplicaSet YAML
- Docker & Kubernetes course
- Intermediate
- Lesson 32/82
- 4 min
Learn the ReplicaSet YAML structure.
ReplicaSet YAML
The ReplicaSet YAML is very similar to the Deployment's; only kind differs and there's no strategy field:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: api
spec:
replicas: 3
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: api:1.0
ReplicationController
In old sources you may see ReplicationController (rc); it's the ReplicaSet's predecessor and supports only equality-based selectors. It isn't used in new configurations:
# old
kind: ReplicationController
spec:
selector:
app: api
# new
kind: ReplicaSet
spec:
selector:
matchLabels:
app: apiPractice ReplicaSet YAML
Write a ReplicaSet YAML: name api, replicas: 3; selector and 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: 3
selector:
matchLabels:
app: 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 What is the ReplicaSet's apiVersion?
- batch/v1
- replicaset/v1
- apps/v1 Correct answer
- v1
Explanation: Deployment, ReplicaSet, StatefulSet and DaemonSet are in the apps group.
2 Write the object type.
apiVersion: apps/v1
kind: ____
apiVersion: apps/v1
kind: ReplicaSet
Explanation: Type names are case-sensitive.
3 Match.
| Term | Meaning |
|---|---|
ReplicaSet |
apps/v1 |
ReplicationController |
Old predecessor |
matchLabels |
Label matching |
template |
Pod mould |