kubectl基础命令详解

查看资源对象

$ kubectl api-resources

kubectl基础命令详解_第1张图片

经常用到的别名

componentstatuses 		cs  	组件状态
namespaces 				ns  	命名空间
deployments 			deploy	deploy
services				svc		svc
ingresses				ing
cronjobs				cj
events					ev
replicationcontrollers 	rc

查询node状态

[root@node01 ~]# kubectl get node
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   25h   v1.23.9
node01   Ready    <none>                 23h   v1.23.9
node02   Ready    <none>                 23h   v1.23.9

查询组件状态

 [root@node01 ~]# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS    MESSAGE                         ERROR
scheduler            Healthy   ok                              
controller-manager   Healthy   ok                              
etcd-0               Healthy   {"health":"true","reason":""}   

查询apiservice注册信息

[root@node01 ~]# kubectl get apiservice
NAME                                   SERVICE   AVAILABLE   AGE
v1.                                    Local     True        25h
v1.admissionregistration.k8s.io        Local     True        25h
v1.apiextensions.k8s.io                Local     True        25h
v1.apps                                Local     True        25h
v1.authentication.k8s.io               Local     True        25h
v1.authorization.k8s.io                Local     True        25h
v1.autoscaling                         Local     True        25h
v1.batch                               Local     True        25h
v1.certificates.k8s.io                 Local     True        25h
v1.coordination.k8s.io                 Local     True        25h
v1.discovery.k8s.io                    Local     True        25h
v1.events.k8s.io                       Local     True        25h
v1.networking.k8s.io                   Local     True        25h
v1.node.k8s.io                         Local     True        25h
v1.policy                              Local     True        25h
v1.rbac.authorization.k8s.io           Local     True        25h
v1.scheduling.k8s.io                   Local     True        25h
v1.storage.k8s.io                      Local     True        25h
v1beta1.batch                          Local     True        25h
v1beta1.discovery.k8s.io               Local     True        25h
v1beta1.events.k8s.io                  Local     True        25h
v1beta1.flowcontrol.apiserver.k8s.io   Local     True        25h
v1beta1.node.k8s.io                    Local     True        25h
v1beta1.policy                         Local     True        25h
v1beta1.storage.k8s.io                 Local     True        25h
v1beta2.flowcontrol.apiserver.k8s.io   Local     True        25h
v2.autoscaling                         Local     True        25h
v2beta1.autoscaling                    Local     True        25h
v2beta2.autoscaling                    Local     True        25h

查询api的版本

[root@node01 ~]# kubectl api-versions
admissionregistration.k8s.io/v1
apiextensions.k8s.io/v1
apiregistration.k8s.io/v1
apps/v1
authentication.k8s.io/v1
authorization.k8s.io/v1
autoscaling/v1
autoscaling/v2
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1
coordination.k8s.io/v1
discovery.k8s.io/v1
discovery.k8s.io/v1beta1
events.k8s.io/v1
events.k8s.io/v1beta1
flowcontrol.apiserver.k8s.io/v1beta1
flowcontrol.apiserver.k8s.io/v1beta2
networking.k8s.io/v1
node.k8s.io/v1
node.k8s.io/v1beta1
policy/v1
policy/v1beta1
rbac.authorization.k8s.io/v1
scheduling.k8s.io/v1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1

查看所有的命令空间

不指定命令空间默认都会在default
kube-public 中的资源可以被所有人访问

[root@node01 ~]# kubectl get ns
NAME                   STATUS   AGE
default                Active   25h
kube-flannel           Active   25h
kube-node-lease        Active   25h
kube-public            Active   25h
kube-system            Active   25h
kubernetes-dashboard   Active   23h

查询指定的命名空间
-o 可以指定输出的格式

wide 会显示更多的信息

json 显示成json格式

yaml yaml格式

命名空间的 kind 为 Namespace

查询pod

查询所有pod

 kubectl get pods --all-namespaces
 kubectl get pods -A

查询指定某一个命名空间下的pod

[root@node01 ~]# kubectl get pods -n kube-flannel
NAME                    READY   STATUS    RESTARTS   AGE
kube-flannel-ds-7vbkn   1/1     Running   0          24h
kube-flannel-ds-lpfvv   1/1     Running   0          25h
kube-flannel-ds-vtrk8   1/1     Running   0          24h

查询pod详情

kubectl describe pod etcd-master -n kube-system



查询pod处在pending状态,问题解决相关命令

 kubectl -n [namespaces] describe pod [podname]

$  kubectl -n ol describe pod operation-manage-846f756495-gphxp

https://blog.csdn.net/weixin_44412085/article/details/127687800

你可能感兴趣的:(运维,linux,docker,bash)