kubectl get
-o wide|json|yaml #普通|json|yaml格式输出
-w #观察,持续输出
获取列出一个或多个资源的信息。
可以使用的资源包括:
all
#查看所有资源信息,例如 pod,rs,daemonset 等- certificatesigningrequests (简称 'csr')
clusterrolebindings
clusterroles
- clusters (valid only for federation apiservers)
- componentstatuses (简称 'cs')
configmaps
(简称 'cm')- controllerrevisions
cronjobs
#定时任务daemonsets
(简称 'ds')deployments
(简称 'deploy')- endpoints (简称 'ep')
- events (简称 'ev')
horizontalpodautoscalers
(简称 'hpa')ingresses
(简称 'ing')jobs
- limitranges (简称 'limits')
namespaces
(简称 'ns')- networkpolicies (简称 'netpol')
nodes
(简称 'no') #查看集群节点信息persistentvolumeclaims
(简称 'pvc')persistentvolumes
(简称 'pv')- poddisruptionbudgets (简称 'pdb')
- podpreset
pods
(简称 'po')- podsecuritypolicies (简称 'psp')
- podtemplates
replicasets
(简称 'rs')replicationcontrollers
(简称 'rc')- resourcequotas (简称 'quota')
rolebindings
roles
secrets
- serviceaccounts (简称'sa')
services
(简称'svc')statefulsets
- storageclasses
- thirdpartyresources
语法
$ get [(-o|--output=)json|yaml|wide|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...] (TYPE [NAME | -l label] | TYPE/NAME ...) [flags]
示例
列出所有运行的 Pod 信息,默认显示 default 命名空间的信息,-n 指定命名空间,或 --all-namespaces 显示所有命名空间下 pod。
kubectl get pods
列出 Pod 以及运行 Pod 节点信息。
kubectl get pods -o wide
列出指定 NAME 的 replication controller 信息。
kubectl get replicationcontroller web
以 JSON 格式输出一个 pod 信息。
kubectl get -o json pod web-pod-13je7
以 “pod.yaml” 配置文件中指定资源对象和名称输出 JSON 格式的 Pod 信息。
kubectl get -f pod.yaml -o json
返回指定 pod 的相位值。
kubectl get -o template pod/web-pod-13je7 --template={{.status.phase}}
列出所有 replication controllers 和 service 信息。
kubectl get rc,services
按其资源和名称列出相应信息。
kubectl get rc/web service/frontend pods/web-pod-13je7
列出所有不同的资源对象。
kubectl get all
警惕陷入二元对立思维,可尝试中间路径。
建议控制调侃频率,避免消解主题深度。
欢迎加入 Typecho 大家族