jaywcjlove / jaywcjlove/reference

【备忘清单】 请求: K8S 命令

Open
#1,006 0 comments 0 reactions 1 assignee View on GitHub

@jaywcjlove is already working on this.

Since Sep 1, 2025.

request
Dominant language
Dockerfile
Stars
15.3k
Forks
2.2k
Avg merge
2h 17m
Merged PRs (30d)
4

Description

说明项目

K8S 常见命令100个汇总
集群信息
显示 Kubernetes 版本
kubectl version
显示集群信息
kubectl cluster-info
列出集群中的所有节点
kubectl get nodes
查看一个具体的节点详情
kubectl describe node
列出所有命名空间
kubectl get namespaces
列出所有命名空间中的所有 Pod
kubectl get pods --all-namespaces
Pod 诊断
列出特定命名空间中的 Pod
kubectl get pods -n
查看一个 Pod 详情
kubectl describe pod -n
查看 Pod 日志
kubectl logs -n
尾部 Pod 日志
kubectl logs -f -n
在 Pod 中执行命令
kubectl exec -it -n --
Pod 健康检查
检查 Pod 准备情况
kubectl get pods -n -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
检查 Pod 事件
kubectl get events -n --field-selector involvedObject.name=
Service 诊断
列出命名空间中的所有服务
kubectl get svc -n
查看一个服务详情
kubectl describe svc -n
Deployment 诊断
列出命名空间中的所有 Deployment
kubectl get deployments -n
查看一个 Deployment 详情
kubectl describe deployment -n
查看滚动发布状态
kubectl rollout status deployment/ -n
查看滚动发布历史记录
kubectl rollout history deployment/ -n
StatefulSet 诊断
列出命名空间中的所有 StatefulSet
kubectl get statefulsets -n
查看一个 StatefulSet 详情
kubectl describe statefulset -n
ConfigMap 和 Secret 诊断
列出命名空间中的 ConfigMap
kubectl get configmaps -n
查看一个 ConfigMap 详情
kubectl describe configmap -n
列出命名空间中的 Secret
kubectl get secrets -n
查看一个 Secret 详情
kubectl describe secret -n
命名空间诊断
查看一个命名空间详情
kubectl describe namespace
资源使用情况
检查 Pod 的资源使用情况
kubectl top pod -n
检查节点资源使用情况
kubectl top nodes
网络诊断
显示命名空间中 Pod 的 IP 地址
kubectl get pods -n -o custom-columns=POD:metadata.name,IP:status.podIP --no-headers
列出命名空间中的所有网络策略
kubectl get networkpolicies -n
查看一个网络策略详情
kubectl describe networkpolicy -n
持久卷 (PV) 和持久卷声明 (PVC) 诊断
列出 PV
kubectl get pv
查看一个 PV 详情
kubectl describe pv
列出命名空间中的 PVC
kubectl get pvc -n
查看 PVC 详情
kubectl describe pvc -n
节点诊断
获取特定节点上运行的 Pod 列表
kubectl get pods --field-selector spec.nodeName= -n
资源配额和限制
列出命名空间中的资源配额
kubectl get resourcequotas -n
查看一个资源配额详情
kubectl describe resourcequota -n
自定义资源定义 (CRD) 诊断
列出命名空间中的自定义资源
kubectl get -n
查看自定义资源详情
kubectl describe -n
资源伸缩和自动伸缩
Deployment 伸缩
kubectl scale deployment --replicas= -n
设置 Deployment 的自动伸缩
kubectl autoscale deployment --min= --max= --cpu-percent= -n
检查水平伸缩器状态
kubectl get hpa -n
容量诊断
列出按容量排序的持久卷 (PV)
kubectl get pv --sort-by=.spec.capacity.storage
查看 PV 回收策略
kubectl get pv -o=jsonpath='{.spec.persistentVolumeReclaimPolicy}'
列出所有存储类别
kubectl get storageclasses
Pod 网络故障排除
运行网络诊断 Pod(例如 busybox)进行调试
kubectl run -it --rm --restart=Never --image=busybox net-debug-pod -- /bin/sh
测试从 Pod 到特定端点的连接
kubectl exec -it -n -- curl
跟踪从一个 Pod 到另一个 Pod 的网络路径
kubectl exec -it -n -- traceroute
检查 Pod 的 DNS 解析
kubectl exec -it -n -- nslookup
节点污点
列出节点污点
kubectl describe node | grep Taints

提供官网

https://tiaohe.github.io/k8s.html

参考资料 URL

K8S 常见命令100个汇总
集群信息
显示 Kubernetes 版本
kubectl version
显示集群信息
kubectl cluster-info
列出集群中的所有节点
kubectl get nodes
查看一个具体的节点详情
kubectl describe node
列出所有命名空间
kubectl get namespaces
列出所有命名空间中的所有 Pod
kubectl get pods --all-namespaces
Pod 诊断
列出特定命名空间中的 Pod
kubectl get pods -n
查看一个 Pod 详情
kubectl describe pod -n
查看 Pod 日志
kubectl logs -n
尾部 Pod 日志
kubectl logs -f -n
在 Pod 中执行命令
kubectl exec -it -n --
Pod 健康检查
检查 Pod 准备情况
kubectl get pods -n -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
检查 Pod 事件
kubectl get events -n --field-selector involvedObject.name=
Service 诊断
列出命名空间中的所有服务
kubectl get svc -n
查看一个服务详情
kubectl describe svc -n
Deployment 诊断
列出命名空间中的所有 Deployment
kubectl get deployments -n
查看一个 Deployment 详情
kubectl describe deployment -n
查看滚动发布状态
kubectl rollout status deployment/ -n
查看滚动发布历史记录
kubectl rollout history deployment/ -n
StatefulSet 诊断
列出命名空间中的所有 StatefulSet
kubectl get statefulsets -n
查看一个 StatefulSet 详情
kubectl describe statefulset -n
ConfigMap 和 Secret 诊断
列出命名空间中的 ConfigMap
kubectl get configmaps -n
查看一个 ConfigMap 详情
kubectl describe configmap -n
列出命名空间中的 Secret
kubectl get secrets -n
查看一个 Secret 详情
kubectl describe secret -n
命名空间诊断
查看一个命名空间详情
kubectl describe namespace
资源使用情况
检查 Pod 的资源使用情况
kubectl top pod -n
检查节点资源使用情况
kubectl top nodes
网络诊断
显示命名空间中 Pod 的 IP 地址
kubectl get pods -n -o custom-columns=POD:metadata.name,IP:status.podIP --no-headers
列出命名空间中的所有网络策略
kubectl get networkpolicies -n
查看一个网络策略详情
kubectl describe networkpolicy -n
持久卷 (PV) 和持久卷声明 (PVC) 诊断
列出 PV
kubectl get pv
查看一个 PV 详情
kubectl describe pv
列出命名空间中的 PVC
kubectl get pvc -n
查看 PVC 详情
kubectl describe pvc -n
节点诊断
获取特定节点上运行的 Pod 列表
kubectl get pods --field-selector spec.nodeName= -n
资源配额和限制
列出命名空间中的资源配额
kubectl get resourcequotas -n
查看一个资源配额详情
kubectl describe resourcequota -n
自定义资源定义 (CRD) 诊断
列出命名空间中的自定义资源
kubectl get -n
查看自定义资源详情
kubectl describe -n
资源伸缩和自动伸缩
Deployment 伸缩
kubectl scale deployment --replicas= -n
设置 Deployment 的自动伸缩
kubectl autoscale deployment --min= --max= --cpu-percent= -n
检查水平伸缩器状态
kubectl get hpa -n
容量诊断
列出按容量排序的持久卷 (PV)
kubectl get pv --sort-by=.spec.capacity.storage
查看 PV 回收策略
kubectl get pv -o=jsonpath='{.spec.persistentVolumeReclaimPolicy}'
列出所有存储类别
kubectl get storageclasses
Pod 网络故障排除
运行网络诊断 Pod(例如 busybox)进行调试
kubectl run -it --rm --restart=Never --image=busybox net-debug-pod -- /bin/sh
测试从 Pod 到特定端点的连接
kubectl exec -it -n -- curl
跟踪从一个 Pod 到另一个 Pod 的网络路径
kubectl exec -it -n -- traceroute
检查 Pod 的 DNS 解析
kubectl exec -it -n -- nslookup
节点污点
列出节点污点
kubectl describe node | grep Taints

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.