Fields

Prints based on Field values

Print Resource Fields

Motivation

Kubectl Get is able to pull out fields from Resources it queries and format them as output.

This may be useful for scripting or gathering data about Resources from a Kubernetes cluster.

Get

The kubectl get reads Resources from the cluster and formats them as output. The examples in this chapter will query for Resources by providing Get the Resource Type with the Version and Group as an argument. For more query options see Queries and Options.

Kubectl can format and print specific fields from Resources using Json Path.

Example: Print the JSON representation of the first Deployment in the list on a single line

kubectl get deployment.v1.apps -o=jsonpath='{.items[0]}{"\n"}'

you get:

map[apiVersion:apps/v1 kind:Deployment...replicas:1 updatedReplicas:1]]

This ideology can be extended to query out the specific fields in a yaml resource file.


Last modified October 31, 2020: docs render fix (cd35140)