kubectl 命令


# 查看所有 pod 列表, -n 后跟 namespace, 查看指定的命名空間
kubectl get pod kubectl get pod -n kube # 查看 RC 和 service 列表, -o wide 查看詳細信息
kubectl get rc,svc kubectl get pod,svc -o wide kubectl get pod <pod-name> -o yaml # 顯示 Node 的詳細信息
kubectl describe node 192.168.0.212

# 顯示 Pod 的詳細信息, 特別是查看 pod 無法創建的時候的日志
kubectl describe pod <pod-name> eg: kubectl describe pod redis-master-tqds9 # 根據 yaml 創建資源, apply 可以重復執行,create 不行
kubectl create -f pod.yaml kubectl apply -f pod.yaml # 基於 pod.yaml 定義的名稱刪除 pod 
kubectl delete -f pod.yaml # 刪除所有包含某個 label 的pod 和 service
kubectl delete pod,svc -l name=<label-name>

kubectl delete namespace xxx # 刪除所有 Pod kubectl delete pod --all # 查看 endpoint 列表 kubectl get endpoints
kubectl get namespace
# 執行 pod 的 date 命令 kubectl exec <pod-name> -- date kubectl exec <pod-name> -- bash kubectl exec <pod-name> -- ping 10.24.51.9 # 通過bash獲得 pod 中某個容器的TTY,相當於登錄容器 kubectl exec -it <pod-name> -c <container-name> -- bash eg: kubectl exec -it redis-master-cln81 -- bash # 查看容器的日志 kubectl logs <pod-name> kubectl logs -f <pod-name> # 實時查看日志
# 容器日志輸出到文件

   log_pod release-xxxx 10000 > xxxx.txt

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM