Listing resources with labels using kubectl

The kubectl get commands will show you basic information by default, typically the name and status of the resources you're looking for. You can extend the columns that it displays to include specific labels, which can often make it much easier to find what you are looking for when dealing with large numbers of different Pods, deployments, and ReplicaSets. kubectl takes an -L option with a comma-separated list of label keys to show as headers.

If you wanted to show the Pods along with the label keys run and pod-template-hash, the command would be:

kubectl get pods -L run,pod-template-hash

 You then may see output like the following:

NAME READY STATUS RESTARTS AGE RUN POD-TEMPLATE-HASHflask-1908233635-d6stj ...

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.