极简工具箱

免费在线工具 · 本地计算 · 无需上传

kubectl 命令

kubectl 常用命令速查,Pod、Deployment、Service、节点运维全覆盖,复制即用。

广告位(百度联盟)
命令说明示例
kubectl get pods列出 Pod(含 IP)kubectl get pods -n default -o wide
kubectl get all列出命名空间全部资源kubectl get all -n myns
kubectl get svc列出服务kubectl get svc -n myns
kubectl describe pod查看 Pod 详情与事件kubectl describe pod web-7d9f -n myns
kubectl logs -f跟踪容器日志kubectl logs -f web-7d9f -c web -n myns
kubectl exec -it进入容器执行命令kubectl exec -it web-7d9f -c web -n myns -- bash
kubectl apply -f应用 / 更新资源配置kubectl apply -f deploy.yaml
kubectl delete -f删除资源kubectl delete -f deploy.yaml
kubectl create ns创建命名空间kubectl create namespace myns
kubectl config get-contexts查看可用集群上下文kubectl config get-contexts
kubectl config use-context切换当前集群kubectl config use-context prod
kubectl port-forward本地端口转发到 Podkubectl port-forward pod/web 8080:80 -n myns
kubectl scale扩缩容副本数kubectl scale deploy/web --replicas=3 -n myns
kubectl set image更新工作负载镜像kubectl set image deploy/web web=img:2.0 -n myns
kubectl rollout status查看滚动发布状态kubectl rollout status deploy/web -n myns
kubectl rollout undo回滚到上一版本kubectl rollout undo deploy/web -n myns
kubectl rollout restart触发滚动重启kubectl rollout restart deploy/web -n myns
kubectl edit在线编辑资源kubectl edit deploy/web -n myns
kubectl expose将部署暴露为 Servicekubectl expose deploy/web --port=80 --type=ClusterIP
kubectl cp容器与本地互拷文件kubectl cp myns/web-7d9f:/etc/nginx/nginx.conf ./
kubectl top nodes查看节点资源用量kubectl top nodes
kubectl top pods查看 Pod 资源用量kubectl top pods -n myns
kubectl label给节点打标签kubectl label node n1 disktype=ssd
kubectl cordon标记节点不可调度kubectl cordon n1
kubectl drain驱逐并下线节点kubectl drain n1 --ignore-daemonsets --delete-emptydir-data
kubectl uncordon恢复节点可调度kubectl uncordon n1
kubectl patch局部更新资源字段kubectl patch deploy/web -p '{"replicas":2}' -n myns
kubectl auth can-i检查权限是否允许kubectl auth can-i create pods --as=dev
kubectl version查看客户端/服务端版本kubectl version --short

更多速查表

常用在线工具