I noticed that the pods were allocated on the same node. After investigating, I noticed that the key for matchExpressions should be 'name' instead of 'app' because the name of the app is 'my-mongodb-svc' not 'my-mongodb'. Even thought I also tried with 'my-mongodb-svc' and 'app', but it didn't work. When I changed the key to 'name', it worked because the replicaSet has the name 'my-mongodb'.
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app #This should be **name** instead of app
operator: In
values:
- my-mongodb
I noticed that the pods were allocated on the same node. After investigating, I noticed that the key for matchExpressions should be 'name' instead of 'app' because the name of the app is 'my-mongodb-svc' not 'my-mongodb'. Even thought I also tried with 'my-mongodb-svc' and 'app', but it didn't work. When I changed the key to 'name', it worked because the replicaSet has the name 'my-mongodb'.