Kubernetes YAML Cheat Sheet/Get resources by label selector

Use labels to query related objects.

Section: Metadata, Labels, and Annotations

Get resources by label selector

bash
bash
kubectl get pods -l app.kubernetes.io/name=api

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
Add or update label from CLI
Patch a label onto a resource.
OpenIn sheetbashsame section
Labels and annotations example
Common metadata block for selectors and tooling.
OpenIn sheetyamlsame section
Add annotation from CLI
Write metadata without affecting selectors.
OpenIn sheetbashsame section
Explain a field path
Discover valid YAML fields from kubectl.
OpenIn sheetbash1 tag match
Apply YAML file
Create or update resources from a YAML file.
OpenIn sheetbash1 tag match
Apply YAML directory
Apply all manifests in a directory.
OpenIn sheetbash1 tag match