What's the difference in name,run,app in a netpol

Hi kodekloud Team:

podSelector:
  matchLabels:
    name: my-pod
   #run: my-pod
   #app: my-pod

What’s the difference for implementation and in which context should I use an specific variable ?

cheers

There’s no specific rules here for what these are called. It is simply match all the pods that have these label key/values, just as it is for selector in kubnenetes service.

apiVersion: v1
kind: pod
metadata:
   name: pod-one
   labels:
      name: my-pod

would be matched by your selector above (with the other two labels commented).

The basic rule is any pods that have at least the same labels under metadata.labels (they can have more labels) as what is in podSelector.matchLabels will be included.

1 Like

Thanks @Alistair_KodeKloud for the reply. In some exams (I’m not sure if from cka course or/and cka mock exam course), some exercises doesn’t work with the appropiate rule. There is one that you need to put run instead of name. I could search for it latter if you need it, but I’m just curious why in some cases some labels would not work for approval of the lab question. The objects always get’s created btw.

The lab question is just keyed to that label/value pair, is all. As Alistair says, they are otherwise arbitrary.

Some of K8s’ commands tend to create a particular label (“run” for kubecatl run NEW-POD; “app” for k create deploy NEW-DEP), which might explain why some labels are more common than others.

1 Like

Thanks very much @Alistair_KodeKloud and @rob_kodekloud for the answers. I just want to know if when are you creating a netpol the pair label/value could be anything except the especial characters not available in k8s yaml files syntax.

For example could I just put a lablel like “pig: oink” in a deployment or pod, and the netpol would work ? Or needs to be something like run, app, name in the label tag ? Also does this apply to service mesh like istio and consul ?

None, really. The labels you choose are arbitrary. As a best practice, you want them to communicate what the pods are doing, so unless your fellow engineers speak Pig, “oink” won’t tell them much about what the pods are doing :wink:

1 Like

Thanks @rob_kodekloud for the reply :wink:.Have a nice weekend :slight_smile: