What basis selecting/modifying labels under selector & template?

Hello Team,

I just want to know on what basis we are deciding which labels (whether selector or template) should change in the definition file?

For example

one of the replicaset definition file there are two different labels under selector (front-end) and template (nginx) so should match labels under selector with template or vice-versa?

My understanding:

As per topics discuss in the course CKA, selectors labels should create first and match with template labels. There is no problem if both matching by changing any on of them. I think that’s why we’re putting “matchlabels” under the selector labels, Is my understanding is correct?

In realistic situations, you choose your label scheme to make it easier to manage your resources in K8s – to reflect how your organization is structured, how your application is structured, and who’s responsible for different parts of your infrastructure. That’s the important thing.

A lot of things in K8s work by matching the labels of pods, or other resources like nodes. But you choose the labels by the criteria I mentioned above.

In a service, the selector needs to match the target labels. Full stop.

Now, in a problem, where you’re fixing a broken service where they don’t match, which do you change? It’s arbitrary. Usually the problem description will make clear which you need to change. There’s no general rule beyond this one: once you make the needed change, the selector and the template.labels need to match. How you did that depends on the wording of the problem.

Hello Rob,

Thanks for reply…!!

I got it now.