[K8S] 常用查看命令
@查看master组件状态 kubectl get cs[root@k8s-master ~]# kubectl get csWarning: v1 ComponentStatus is deprecated in v1.19+NAMESTATUSMESSAGEERRORcontroller-managerHealthyokschedulerHealthyoketcd-0...
@查看master组件状态 kubectl get cs
[root@k8s-master ~]# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy {"health":"true"}
[root@k8s-master ~]#
@查看资源 kubectl api-resources
说明:可以查看各个资源的版本,写yaml文件会用到;可以看资源的缩写
[root@k8s-master ~]# kubectl api-resources
NAME SHORTNAMES APIVERSION NAMESPACED KIND
bindings v1 true Binding
componentstatuses cs v1 false ComponentStatus
configmaps cm v1 true ConfigMap
endpoints ep v1 true Endpoints
events ev v1 true Event
limitranges limits v1 true LimitRange
namespaces ns v1 false Namespace
nodes no v1 false Node
persistentvolumeclaims pvc v1 true PersistentVolumeClaim
persistentvolumes pv v1 false PersistentVolume
pods po v1 true Pod
……
daemonsets ds apps/v1 true DaemonSet
deployments deploy apps/v1 true Deployment
……
@查看资源信息,kubectl get --help,kubectl describe --help
kubectl get <resource>
kubectl describe <resource> <name>
kubectl get pods
kubectl get pods -o wide 查看详细信息
kubectl get pods <pod name> 查看具体的pod
kubectl get pods --show-labels 查看标签
kubectl get pods -l <key>=<value> 查看具有某标签的pod
kubectl describe pods <pod name> 查看具体pod的详细信息
kubectl get pod,deploy,svc 查看pod,deployment和service
@查看控制平面和集群服务 kubectl cluster-info
[root@k8s-master ~]# kubectl cluster-info
Kubernetes control plane is running at https://192.168.231.121:6443
KubeDNS is running at https://192.168.231.121:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://192.168.231.121:6443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@k8s-master ~]#
[root@k8s-master ~]# kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 13d
metrics-server ClusterIP 10.96.228.107 <none> 443/TCP 13d
[root@k8s-master ~]#
@查看Node、Pod资源消耗,kubectl top ...
kubectl top nodes
kubectl top node <node name>
kubectl top pods
kubectl top pod <pod name>
[root@k8s-master ~]# kubectl top nodes k8s-node1
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
k8s-node1 62m 3% 773Mi 44%
[root@k8s-master ~]#
[root@k8s-master ~]# kubectl top pods --sort-by=cpu
NAME CPU(cores) MEMORY(bytes)
java-demo-56d54df448-ptww2 2m 162Mi
java-demo-56d54df448-r5rv2 2m 168Mi
java-demo-56d54df448-92n5q 2m 160Mi
nginx-58f8c48d58-48xbn 0m 2Mi
web-96d5df5c8-vjbzv 0m 4Mi
web-96d5df5c8-l5m9f 0m 2Mi
web-96d5df5c8-nqj6z 0m 2Mi
[root@k8s-master ~]# kubectl top pods web-96d5df5c8-nqj6z
NAME CPU(cores) MEMORY(bytes)
web-96d5df5c8-nqj6z 0m 2Mi
[root@k8s-master ~]#
@查看日志
说明: kubeadm部署方式,kubelet是systemd守护进程管理,其它是容器化部署
[root@k8s-master ~]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-97769f7c7-xh7j7 1/1 Running 6 13d
calico-node-58ck4 1/1 Running 8 13d
calico-node-q6qxm 1/1 Running 6 13d
calico-node-vmmv5 1/1 Running 6 13d
coredns-7f89b7bc75-mgtnj 1/1 Running 6 13d
coredns-7f89b7bc75-wkrjq 1/1 Running 6 13d
etcd-k8s-master 1/1 Running 6 13d
kube-apiserver-k8s-master 1/1 Running 6 13d
kube-controller-manager-k8s-master 1/1 Running 1 34h
kube-proxy-clmzc 1/1 Running 6 13d
kube-proxy-f4mk4 1/1 Running 6 13d
kube-proxy-s7n6w 1/1 Running 6 13d
kube-scheduler-k8s-master 1/1 Running 1 34h
metrics-server-84f9866fdf-9l6rt 1/1 Running 3 2d
[root@k8s-master ~]#
kubelet => journalctl -u kubelet
kubectl logs <pod name>
kubectl logs -f <pod name>
kubectl logs -f <pod name> -c <container name> 多个容器不指定默认进入第一个
进入容器终端 kubectl exec -it <pod name> -c <container name> -- bash
更多推荐
所有评论(0)