What Are The Kubernetes Concepts “pod label,” “label selector,” and “pod selector”?

What is the difference between these three two-word terms "pod label," "label selector," and "pod selector"?

This answer provides details on what these are and provides some information on how they are different.

pod label: It is an inherent attribute of the pod. It can be changed via a command like this: kubectl label pod new-podlabel version=5.5 These statements were based on Assistanz.com. These may match with what is usually referred to as a "label selector" in a ReplicationController.

label selector: These are often categories, non-unique and common across multiple pods, that are arbitrarily designed by a human engineer and are not indicative of an underlying pod's attributes. They are one of three parts of a ReplicationController.

One way to think of it is that it is the pod label (an attribute of a pod) from the reference point of a server running the "kubectl" command. The "kubectl" command can filter pods based on their selectable "label selector" values that match the respective filter value. Also note that the ReplicaController's scope is composed of pods that are designated by their label selectors (page 92 of Kubernetes in Action by Luksa). An optimal use of this is to constrain certain pods to run on certain nodes. Kubernetes provides the benefit of hardware redundancy (colocation in two or more hosts). While jobs can run on servers without having GPU acceleration or solid state drives, servers with these features are optimal for certain task-scheduling. High-quality servers can be leveraged frequently whereas commodity servers can be dormant as backups based on label selectors and well-designed kubectl command invocation (page 73 of Kubernetes in Action by Luksa). To learn more, see this posting.

In most, and perhaps all, contexts, we do not think there is a difference between pod label and label selector.

If you run the kubectl describe svc kubia command, you will see an attribute for "Labels" and a separate attribute for "Selector".

pod selector: This is a reference to something that picks (or selects) a pod. It can be defined in a pod template or in what is less recommended -- a ReplicationController .yaml (page 93 of Kubernetes in Action by Luksa). If you run the "kubectl describe svc kubia" command, you will see an attribute for "Labels" and a separate attribute for "Selector". Pod selectors are needed for Kubernetes to automatically create a service's "Endpoints resource" (page 132 of Kubernetes in Action by Luksa).

A "Service" exposes a pod to a socket (inside front cover of Kubernetes in Action). To change a Service's pod selector, run this command: "kubectl set selector" (page 253 of Kubernetes in Action by Luksa).

Here is an example of pod selectors to give some context. The official Kubernetes website has this excerpt of key value pairs:

- {key: tier, operator: In, values: [cache]}
- {key: environment, operator: NotIn, values: [dev]}"

The external link clarifies that "matchExpressions is a list of pod selector requirements. "

Leave a comment

Your email address will not be published. Required fields are marked *