StaffCoder
Kubernetes
15 modules · 60 challengesSign up
Module 3 · Labels, Selectors & Annotations

Annotations for Machinery

easyObject AnnotationsMetadata Management—No data yet

Problem statement

The deploy metadata - which ticket authorised it, which team owns it, which build went out, what actually changed - lives in a spreadsheet. The spreadsheet says nothing about what is running right now, and nothing that is running says anything about the spreadsheet. The namespace fleet-meta runs three labeled workloads. Put the deploy record on the object it describes.

About this exercise

An annotation is a key/value pair in an object's metadata, sitting right beside the labels and behaving nothing like them.

  • A label exists to be selected on. That is why it is constrained: a value is at most 63 characters, and only alphanumerics, -, _ and .. A build JSON blob or a sentence simply cannot be a label value.
  • An annotation exists to be read. It is arbitrary text - long strings, whole JSON documents, URLs, timestamps - and no selector can see it. Nothing indexes it, so nothing constrains it.

That is the whole division of labour: labels are for the identity you query on, annotations are for the metadata some human or tool reads afterwards. Tools rely on this - ingress controllers, autoscalers and deploy systems all read their configuration out of annotations, which is why the fleet's own bookkeeping belongs there too.

The rules that govern changing them are the same as for labels: setting a key that already has a value is refused unless overwriting is intended, and removing a key is its own operation rather than setting it empty.

kubectl annotate --help is the reference.

How this project is graded

The grader reads the annotations off the live pod and compares them byte for byte - the JSON exactly as you attached it, the long sentence whole and unwrapped. It also runs a selector against the annotation keys and requires it to find nothing.

What you will build

The deploy record on pod checkout-web in fleet-meta, exactly these keys and values:

deploy.fleet/ticket           OPS-4417        (later updated - see Step 3)
deploy.fleet/owner            payments-platform
deploy.fleet/build            {"commit":"9f2c1ab","pipeline":41,"artifact":"checkout-web-1.8.3"}
deploy.fleet/change-summary   rolled the checkout web tier onto the new payment gateway after the january incident

And four readback files in answers/, listed in answers/questions.md:

build.json           the value of deploy.fleet/build, exactly as the cluster holds it
change-summary.txt   the value of deploy.fleet/change-summary, exactly, on one line
by-annotation.txt    the pods a label selector for the key deploy.fleet/ticket returns
by-label.txt         the pods in the web tier, one name per line, sorted ascending

Step 1 - the record goes on the object

Attach all four annotations to checkout-web. Two of them are things a label could never hold: one is a JSON document, and one is a sentence well past the 63-character label limit. Both must land whole, character for character, including the quotes and braces.

annotation_set_attached_to_the_pod, structured_value_stored_byte_exact and value_longer_than_the_label_limit_stored_whole should pass

Step 2 - reading it back

Write the JSON value into answers/build.json and the long sentence into answers/change-summary.txt, each holding exactly what the cluster holds and nothing else - no surrounding object, no key name, no re-indenting.

readback_files_match_the_cluster should pass

Step 3 - one changes, one goes

The ticket was superseded: deploy.fleet/ticket becomes OPS-4502. Nothing else on the pod may move - the owner, the build JSON and the change summary must still read exactly as they did. Separately, deploy.fleet/runbook points at a wiki that no longer exists; it must be gone from the object, and everything else must survive it.

update_changes_only_the_target_key and removed_key_is_gone_and_the_rest_remain should pass

Step 4 - invisible to selectors

Ask the cluster for the pods that a label selector for the key deploy.fleet/ticket matches, and save the result to answers/by-annotation.txt. It is a legal selector and it will match nothing, because a selector reads labels and never annotations. Then save the web tier to answers/by-label.txt - the same set as before the annotations existed.

annotations_are_invisible_to_selectors should pass

When every test passes

You have:

  • The deploy record attached to the object it describes instead of a spreadsheet beside it
  • Structured and over-length values stored intact, where a label would have refused them
  • One key updated and one retired without disturbing the ones next to them
  • Proof that annotations carry weight for readers and none at all for selectors

You do not have yet:

  • A fleet actually run this way. Labeling to scheme, answering every operational question by selector and carrying machine metadata is the next exercise, on a fleet that starts out unmanaged.

Verify

Click Test after every step.

More in Labels, Selectors & Annotations

See the module
Labeling SchemeBring an inconsistently labeled namespace to one label scheme - applied at creation, corrected on live objects, a retired key removed, and read back from the cluster.—No data yeteasySelector QueriesAnswer seven operational questions about a labeled namespace with equality and set-based selectors - in, notin, exists - including the empty result and the objects missing the key.—No data yeteasyFleet BookkeepingBring an unmanaged namespace under one label scheme, attach the machine-readable deploy record, and answer every fleet operation by selector - proven by an object the grader adds behind your back.—No data yeteasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.