欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

kubectl get命令

程序员文章站 2024-03-11 16:33:01
...

通过kubectl get --help查看详细用法

一、命令格式

kubectl get resource名称

二、resource列表

  • all
  • certificatesigningrequests (aka ‘csr’)
  • clusterrolebindings
  • clusterrol
  • componentstatuses (aka ‘cs’)
  • configmaps (aka ‘cm’)
  • controllerrevisions
  • cronjobs
  • customresourcedefinition (aka ‘crd’)
  • daemonsets (aka ‘ds’)
  • deployments (aka ‘deploy’)
  • endpoints (aka ‘ep’)
  • events (aka ‘ev’)
  • horizontalpodautoscalers (aka ‘hpa’)
  • ingresses (aka ‘ing’)
  • jobs
  • limitranges (aka ‘limits’)
  • namespaces (aka ‘ns’)
  • networkpolicies (aka ‘netpol’)
  • nodes (aka ‘no’)
  • persistentvolumeclaims (aka ‘pvc’)
  • persistentvolumes (aka ‘pv’)
  • poddisruptionbudgets (aka ‘pdb’)
  • podpreset
  • pods (aka ‘po’)
  • podsecuritypolicies (aka ‘psp’)
  • podtemplates
  • replicasets (aka ‘rs’)
  • replicationcontrollers (aka ‘rc’)
  • resourcequotas (aka ‘quota’)
  • rolebindings
  • roles
  • secrets
  • serviceaccounts (aka ‘sa’)
  • services (aka ‘svc’)
  • statefulsets (aka ‘sts’)
  • storageclasses (aka ‘sc’)

三、可选参数

用不同的格式查看
-o wide/yaml/json

查看指定的命名空间

-n 命名空间

四、 示例

kubectl get namespace
查看所有命名空间

$ kubectl get namespace
NAME          STATUS   AGE
admin         Active   7d
default       Active   7d1h
kube-public   Active   7d1h
kube-system   Active   7d1h
opcs          Active   7d
zenap         Active   3h48m

kubectl get componentstatuses
查看Master状态

$ kubectl get componentstatuses
NAME                 STATUS    MESSAGE              ERROR
controller-manager   Healthy   ok
scheduler            Healthy   ok
etcd-0               Healthy   {"health": "true"}
etcd-1               Healthy   {"health": "true"}
etcd-2               Healthy   {"health": "true"}

kubectl -n ns1 get pods
查找namespace为ns1的所有pod

kubectl -n ns1 get pods -o wide
NAME                                                            READY   STATUS    RESTARTS   AGE     IP              NODE                  NOMINATED NODE   READINESS GATES
apds-apds-design-1-4tmkn                                        2/2     Running   0          3h18m   172.30.2.176    6600-db8-0-f101--19   <none>           <none>

kubectl get -o wide pod pod1 -n ns1
获取名字为pod1的pod的信息,并指定namespace为ns1,并以wide格式输出

$ kubectl -n ns1 get  pods pod1  -o wide
NAME                       READY   STATUS    RESTARTS   AGE     IP              NODE                  NOMINATED NODE   READINESS GATES
pod1   1/1     Running   0          3h26m   100.100.0.117   6600-db8-0-f101--18   <none>           <none>

kubectl get rc,services -n zenap
同时获取所有的rc和service
rc是上文中replicationcontrollers的缩写

$ $ kubectl get rc,services -n zenap
NAME                                                                            DESIRED   CURRENT   READY   AGE
replicationcontroller/apds-apds-design-1                                        1         1         1       3h38m
replicationcontroller/backup-backup-iui-1                                       1         1         1       3h38m


kubectl get all -n zenap
获取所有resource

kubectl get all -n zenap
NAME                                                                READY   STATUS    RESTARTS   AGE
pod/apds-apds-design-1-4tmkn                                        2/2     Running   0          3h35m
pod/backup-backup-iui-1-hdkzv                                       1/1     Running   0          3h34m
...
NAME                                                                            DESIRED   CURRENT   READY   AGE
replicationcontroller/apds-apds-design-1                                        1         1         1       3h35m
replicationcontroller/backup-backup-iui-1                                       1         1         1       3h34m

相关标签: kubectl