You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kubernetes-hands-on/06-label-annotation
antoinegauvain a5b4383297
Various fixes (#57)
* fix: fix internal service filename in 08-service section

* fix: typo

* fix: fix markdownlint in CI

* fix: typo

* fix: typo

* fix: `environment variables`, not `environmental`

* fix: typo & missing punctuation

* fix: `much` not `many`

* fix: `lets` not `let's`

* fix: typo

* fix: typo

* fix: phrasing

* fix: typo

* fix: typo

* fix: mysql operator manifest api version

got this error while trying to run it as is:

error: unable to recognize "20-operators/01-mysql-operator.yml": no matches for
kind "Deployment" in version "apps/v1beta1"

* fix: spelling
4 years ago
..
01-simple-pod.yml chore: lint yaml (#19) 5 years ago
02-nginx.yml chore: lint yaml (#19) 5 years ago
README.md Various fixes (#57) 4 years ago

README.md

Naming things: label and annotation

Introduction

In this section we will learn how to name things in Kubernetes, and how to find them again.

Labels are the way to organize objects in Kubernetes. The labels are a list of key/value. Annotations are a way to mark objects in Kubernetes, it's also a list of key/value.

They seem the same. The major difference is that you can query Kubernetes based on labels. On the other hand, annotations are not limited on characters used for labels.

Valid label keys have two segments: an optional prefix and name, separated by a slash /. The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character [a-z0-9A-Z] with dashes -, underscores _, dots ., and alphanumerics between. The prefix is optional. If specified, the prefix must be a DNS subdomain: a series of DNS labels separated by dots ., not longer than 253 characters in total, followed by a slash /.

Valid label values must be 63 characters or less and must be empty or begin and end with an alphanumeric character [a-z0-9A-Z] with dashes -, underscores _, dots ., and alphanumerics between.

Labels in action

Apply the manifest 01-simple-pod.yml. It is the same as 05-pods/01-simple-pod.yml but with 2 labels:

  • env: production
  • tier: backend

Apply the manifest 02-nginx.yml. It is a simple nginx with 2 labels:

  • env: production
  • tier: frontend

Let's list all the pods that are in the env=production:

$ kubectl get pods -l env=production
NAME             READY     STATUS    RESTARTS   AGE
nginx            1/1       Running   0          13s
simple-pod   1/1       Running   0          13s

Let's list all the pods that are in the env=production,tier=frontend:

$ kubectl get pods -l env=production,tier=frontend
NAME      READY     STATUS    RESTARTS   AGE
nginx     1/1       Running   0          1m

Those queries we call them selector in the Kubernetes jargon. We will use them later on with deployments.

Clean up

kubectl delete pod --all