Kubernetes YAML Cheat Sheet/Labels and annotations example

Common metadata block for selectors and tooling.

Section: Metadata, Labels, and Annotations

Labels and annotations example

yaml
yaml
metadata:
  name: api
  namespace: prod
  labels:
    app.kubernetes.io/name: api
    app.kubernetes.io/component: backend
    app.kubernetes.io/part-of: storefront
    tier: web
  annotations:
    kubectl.kubernetes.io/default-container: api
    reloader.stakater.com/auto: "true"
Explanation

Labels are queryable and support selectors; annotations hold arbitrary metadata that tools and operators consume.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Metadata, Labels, and Annotations
Get resources by label selector
Use labels to query related objects.
OpenIn sheetbashsame section
Add or update label from CLI
Patch a label onto a resource.
OpenIn sheetbashsame section
Add annotation from CLI
Write metadata without affecting selectors.
OpenIn sheetbashsame section
Minimal Pod manifest
Smallest practical Pod YAML shape.
Override container command and args
Set entrypoint-style command in YAML.
Basic Deployment YAML
Run a replicated stateless workload.