In the ReplicaSet, .spec.template.metadata.labels must match spec.selector, or it will be rejected by the API.
The .spec.selector field is a label selector. As discussed earlier these are the labels used to identify potential Pods to acquire. In our frontend.yaml example, the selector was:
Note: For 2 ReplicaSets specifying the same .spec.selector but different .spec.template.metadata.labels and .spec.template.spec fields, each ReplicaSet ignores the Pods created by the other ReplicaSet.
Replicas
apiVersion: apps/v1 | |
kind: ReplicaSet | |
metadata: | |
name: frontend | |
labels: | |
app: guestbook | |
tier: frontend | |
spec: | |
# modify replicas according to your case | |
replicas: 3 | |
selector: | |
matchLabels: | |
tier: frontend | |
template: | |
metadata: | |
labels: | |
tier: frontend | |
spec: | |
containers: | |
- name: php-redis | |
image: scmgalaxy/nginx-devopsschoolv1 | |
apiVersion: apps/v1 | |
kind: ReplicaSet | |
metadata: | |
name: my-replicaset | |
spec: | |
replicas: 2 | |
selector: | |
matchLabels: | |
app: my-app | |
template: | |
metadata: | |
labels: | |
app: my-app | |
spec: | |
containers: | |
- name: my-container | |
image: nginx |









I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND