Chapter 3. Organize, Grow, and Go
Once you start creating pods, you’ll quickly discover how important it is to organize them. As your clusters grow in size and scope, you’ll need to use this organization to manage things effectively. More than that, however, you will need a way to find pods that have been created for a specific purpose and route requests and data to them. In an environment where things are being created and destroyed with some frequency, that’s harder than you think!
Better Living through Labels, Annotations, and Selectors
Kubernetes provides two basic ways to document your infrastructure—labels and annotations.
Labels
A label is a key/value pair that you assign to a Kubernetes object (a pod in this case). You can use pretty well any name you like for your label, as long as you follow some basic naming rules. In this case, the label will decorate a pod and will be part of the pod.yaml file you might create to define your pods and containers.
Let’s use an easy example to demonstrate. Suppose you wanted to identify a pod as being part of the front-end tier of your application. You might create a label named tier and assign it a value of frontend—like so:
“labels”: { “tier”: “frontend” }
The text “tier” is the key, and the text “frontend” is the value.
Keys are a combination of zero or more prefixes followed by a “/” character followed by a name string. The prefix and slash are optional. Two examples:
“application.game.awesome-game/tier” “tier”
In the first case, ...
Get Kubernetes now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.