7 Organizing Pods and Other Resources using Namespaces and Labels

 

This chapter covers

  • Using namespaces to split a physical cluster into virtual clusters
  • Organizing objects using labels
  • Using label selectors to perform operations on subsets of objects
  • Using label selectors to schedule Pods onto specific nodes
  • Using field selectors to filter objects based on their properties
  • Annotating objects with additional non-identifying information

A Kubernetes cluster is usually used by many teams. How should these teams deploy objects to the same cluster and organize them so that one team doesn’t accidentally modify the objects created by other teams?

And how can a large team deploying hundreds of microservices organize them so that each team member, even if new to the team, can quickly see where each object belongs and what its role in the system is? For example, to which application does a Pod belong.

These are two different problems. Kubernetes solves the first with object namespaces, and the other with object labels. Both are explained in this chapter.

NOTE

7.1 Organizing objects into Namespaces

7.1.1 Listing namespaces and the objects they contain

7.1.2 Creating namespaces

7.1.3 Managing objects in other namespaces

7.1.4 Understanding the (lack of) isolation between namespaces

7.1.5 Deleting namespaces

7.2 Organizing Pods with labels

7.2.1 Introducing labels

7.2.2 Adding labels to Pods

7.2.3 Label syntax rules

7.2.4 Using standard label keys

7.3 Filtering objects with label selectors

7.3.1 Using label selectors for object management with kubectl

7.3.2 Using label selectors in object manifests

7.4 Filtering objects with field selectors

7.4.1 Using a field selector in kubectl

7.4.2 Using field selectors in object manifests

7.5 Annotating objects

7.5.1 Introducing object annotations

7.5.2 Adding annotations to objects

7.5.3 Inspecting an object’s annotations

7.5.4 Updating and removing annotations

7.6 Summary