kubectl get parameter usage

Detailed explanation of kubectl get --help parameters

-o yaml   ( view pod information in yaml format )

Example: View etcd-hxe pod information in yaml format

kubectl get  pod etcd-hxe -o yaml -n kube-system

describe ( view service details )

Example: View detailed information of nginx

kubectl describe pods nginx

--field-selector ( filter out pods with specified information )

Example: Filter out the running pods

kubectl get pods --field-selector status.phase=Running -A

Example: filter out pods with a specified name

kubectl get pods --field-selector metadata.name=kube-flannel-ds-9txjl -n kube-flannel

--show-labels ( view pod labels )

Example: View labels of all pods

kubectl get pods -A --show-labels

-L ( view label information )

Example: view app label content

kubectl get pods -A -L  component

 -l (specify labels)

Example: filter out tags with controller-revision-hash equal to c99668656

kubectl get pods -A -l controller-revision-hash=c99668656

--no-headers ( remove the first line of display information )

Example: remove the first line of display information

kubectl get pods --no-headers

-o  specifies the format to output pod information

Example: display pod information in json format

kubectl get  pod etcd-hxe -o json -n kube-system

Example: display pod information in yaml format 

kubectl get  pod etcd-hxe -o yaml -n kube-system

--sort-by ( display in sorted order )

Example: Sort and display by pod creation time

kubectl get pods -A --sort-by=metadata.creationTimestamp

Extension: original title of cka

Use creationTimestamp (creation time) to sort and list all pods, store the output content under /opt, and do not further operate him

kubectl get pods -A --sort-by=metadata.creationTimestamp > /opt/2.txt

Guess you like

Origin blog.csdn.net/m0_65307735/article/details/128366834