集群信息:
显示 Kubernetes 版本:kubectl version
显示集群信息:kubectl cluster-info
列出集群中的所有节点:kubectl get nodes
查看一个具体的节点详情:kubectl describe node <node-name>
列出所有命名空间:kubectl get namespaces
列出所有命名空间中的所有 pod:kubectl get pods --all-namespaces
Pod 诊断:
列出特定命名空间中的 pod:
kubectl get pods -n <namespace>
查看一个 Pod 详情:
kubectl describe pod <pod-name> -n <namespace>
查看 Pod 日志:
kubectl logs <pod-name> -n <namespace>
尾部 Pod 日志:
kubectl logs -f <pod-name> -n <namespace>
在 pod 中执行命令:
kubectl exec -it <pod-name> -n <namespace> -- <command>
Pod 健康检查:
检查 Pod 准备情况:
kubectl get pods <pod-name> -n <namespace> -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
检查 Pod 事件:
kubectl get events -n <namespace> --field-selector involvedObject.name=<pod-name>
Service诊断:
列出命名空间中的所有服务:
kubectl get svc -n <namespace>
查看一个服务详情:
kubectl describe svc <service-name> -n <namespace>
Deployment诊断:
列出命名空间中的所有Deployment:
kubectl get deployments -n <namespace>
查看一个Deployment详情:
kubectl describe deployment <deployment-name> -n <namespace>
查看滚动发布状态:
kubectl rollout status deployment/<deployment-name> -n <namespace>
查看滚动发布历史记录:
kubectl rollout history deployment/<deployment-name> -n <namespace>
StatefulSet诊断:
列出命名空间中的所有 StatefulSet:
kubectl get statefulsets -n <namespace>
查看一个 StatefulSet详情:
kubectl describe statefulset <statefulset-name> -n <namespace>
ConfigMap 和Secret诊断:
列出命名空间中的 ConfigMap:
kubectl get configmaps -n <namespace>
查看一个ConfigMap详情:
kubectl describe configmap <configmap-name> -n <namespace>
列出命名空间中的 Secret:
kubectl get secrets -n <namespace>
查看一个Secret详情:
kubectl describe secret <secret-name> -n <namespace>
命名空间诊断:
查看一个命名空间详情:
kubectl describe namespace <namespace-name>
资源使用情况:
检查 pod 的资源使用情况:
kubectl top pod <pod-name> -n <namespace>
检查节点资源使用情况:
kubectl top nodes
网络诊断:
显示命名空间中 Pod 的 IP 地址:
kubectl get pods -n <namespace> -o custom-columns=POD:metadata.name,IP:status.podIP --no-headers
列出命名空间中的所有网络策略:
kubectl get networkpolicies -n <namespace>
查看一个网络策略详情:
kubectl describe networkpolicy <network-policy-name> -n <namespace>
持久卷 (PV) 和持久卷声明 (PVC) 诊断:
列出PV:
kubectl get pv
查看一个PV详情:
kubectl describe pv <pv-name>
列出命名空间中的 PVC:
kubectl get pvc -n <namespace>
查看PVC详情:
kubectl describe pvc <pvc-name> -n <namespace>
节点诊断:
获取特定节点上运行的 Pod 列表:
kubectl get pods --field-selector spec.nodeName=<node-name> -n <namespace>
资源配额和限制:
列出命名空间中的资源配额:
kubectl get resourcequotas -n <namespace>
查看一个资源配额详情:
kubectl describe resourcequota <resource-quota-name> -n <namespace>