Display one or many resources

Usage:

kubectl get -f FILENAME
kubectl get TYPE
kubectl get TYPE NAME
kubectl get TYPE -l label

Options:

-A, —all-namespaces=false: If present, list the requested object(s) across all namespaces.
-f, —filename=[]: Filename, directory, or URL to files identifying the resource to get from a server.
-L, —label-columns=[]: (指定标签的key作为列名)Accepts a comma separated list of labels that are going to be presented as columns.
-o, —output=’’: Output format. One of: json|yaml|wide|name等等
-l, —selector=’’: (label selector)Selector (label query) to filter on
—show-labels=false: When printing, show all labels as the last column

Examples:

List all pods in ps output format.
kubectl get pods

List all pods in ps output format with more information (such as node name).
kubectl get pods -o wide

List a pod identified by type and name specified in “pod.yaml” in JSON output format.
kubectl get -f pod.yaml -o json

List all replication controllers and services together in ps output format.
kubectl get rc,services

通过列出集群节点查看集群是否在运行
kubectl get nodes

使用-o ymal选项获取 pod 的 YAML 定义:
kubectl get pods <POD> -o yaml

显示资源所有的标签
kubectl get TYPE NAME --show-labels

只显示资源指定的标签( label key):即将label中的key作为一个列进行显示
kubectl get TYPE NAME -L label1,label2...

列出集群中的所有namespace:
kubectl get ns