Kubernetes

Label & Selector Builder

Build matchLabels and matchExpressions alongside the kubectl -l form, with validation.

Equality labels

These become matchLabels, and key=value on the command line.

Recommended labels

Set-based rules
Selector

Command line

kubectl -l
kubectl get pods -l 'app.kubernetes.io/name=api,app.kubernetes.io/component=backend,environment in (staging,production)'

Manifest

Deployment, Service, NetworkPolicy
selector:
  matchLabels:
    app.kubernetes.io/name: api
    app.kubernetes.io/component: backend
  matchExpressions:
    - key: environment
      operator: In
      values:
        - staging
        - production

Labels to apply

on the objects this should match
labels:
  app.kubernetes.io/name: api
  app.kubernetes.io/component: backend

ValidKeys and values satisfy the API server's rules.