Assuming deployment, replicaSet and pod are all 1:1:1 mapping.
deployment ==> replicaSet ==> Pod
When we do deployment, replicaSet adds pod-template-hash label to pods. So, this looks enough for a replicaSet to check if enough pods are running. Then what is the significance of replicaSet matchLabels selector? Why is it mandatory?
To explain for better understanding
For ex: I deploy an app with these labels. 2 pods are running
spec:
replicas: 2
selector:
matchLabels:
app: nginx-app
Now change label value of pod-template-hash to something else for one of the pods (changing to testing here). Now we immediately see another pod started. So replicaSet does not seem to care about selector.matchLabels
NAME READY STATUS RESTARTS AGE LABELS
pod/nginx-app-b8b875889-cpnnr 1/1 Running 0 53s app=nginx-app,pod-template-hash=testing
pod/nginx-app-b8b875889-jlk6m 1/1 Running 0 53s app=nginx-app,pod-template-hash=b8b875889
pod/nginx-app-b8b875889-xblqr 1/1 Running 0 11s app=nginx-app,pod-template-hash=b8b875889
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE LABELS
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 151d component=apiserver,provider=kubernetes
NAME READY UP-TO-DATE AVAILABLE AGE LABELS
deployment.apps/nginx-app 2/2 2 2 53s app=nginx-app
NAME DESIRED CURRENT READY AGE LABELS
replicaset.apps/nginx-app-b8b875889 2 2 2 53s app=nginx-app,pod-template-hash=b8b875889