chapter ten

10 Organizing objects 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 config map or a secret belong.

These are two different problems. Kubernetes solves the first with object namespaces, and the other with object labels. In this chapter, you will learn about both.

NOTE

10.1 Organizing objects into Namespaces

10.1.1 Listing namespaces and the objects they contain

10.1.2 Creating namespaces

10.1.3 Managing objects in other namespaces

10.1.4 Understanding the (lack of) isolation between namespaces

10.1.5 Deleting namespaces

10.2 Organizing pods with labels

10.2.1 Introducing labels

10.2.2 Attaching labels to pods

10.2.3 Label syntax rules

10.2.4 Using standard label keys

10.3 Filtering objects with label selectors

10.3.1 Using label selectors for object management with kubectl

10.3.2 Utilizing label selectors within Kubernetes API objects

10.4 Annotating objects

10.4.1 Introducing object annotations

10.4.2 Adding annotations to objects

10.4.3 Inspecting an object’s annotations