Skip to content

Latest commit

 

History

History
31 lines (17 loc) · 1.25 KB

label-and-selector.md

File metadata and controls

31 lines (17 loc) · 1.25 KB

Label and Selector

Labels allow for objects to be selected, which may not share other characteristics. For example, if a developer were to label their pods using their name, they could affect all of their pods, regardless of the application or deployment the pods were using.

Labels are how operators, also known as watch-loops, track and manage objects. As a result, if you were to hard-code the same label for two objects, they may be managed by different operators and cause issues. For example, one deployment may call for ten pods, while another with the same label calls for five. All the pods would be in a constant state of restarting, as each operator tries to start or stop pods until the status matches the spec.

Consider the possible ways you may want to group your pods and other objects in production. Perhaps you may use development and production labels to differentiate the state of the application. Perhaps you may want to add labels for the department, team, and primary application developer.

Add Labels

Kubectl label pod <pod_name> key1=value1

# OR

kubectl label -l key1=value1 key2=value2
# -l for filtering based on labels

Remove Labels

kubectl label pod <pod_name> key1-

# OR

kubectl label -l key1=value1 key2-