k8s常用命令

1 查看集群节点信息
kubectl get nodes

2 删除节点
  2.1 先卸载节点node1
  kubectl drain node1 --delete-local-data --force --ignore-daemonsets
  2.2 再删除节点node1
  kubectl delete nodes node1

3. 在主节点创建令牌
kubeadm token create --print-join-command

4. 获取所有命名空间
  4.1 kubectl get namespaces  或  kubectl get ns
  4.2 获取命名空间为dev的状态
    kubectl get ns dev

5. 创建命名空间xxx
kubectl create ns xxx

6. 删除命名空间xxx
kubectl delete ns xxx

7. 查看xxx命名空间详情
kubectl describe ns xxx

8. 获取所有pods
kubectl get pods -A

9. 获取xxx命名空间的所有pods
kubectl get pods --namespace xxx
  
10 获取所有状态为Evicted状态的节点
kubectl get pods --all-namespaces | grep Evicted

11 删除命名空间为:dev的所有状态为Evicted状态的节点
kubectl get pods --namespace=dev | grep Evicted | awk '{print $1}' | xargs kubectl delete pod --namespace=dev

12 删除所有命名空间的所有状态为Evicted状态的节点
kubectl get pods --all-namespaces | grep Evicted | awk '{print $1}' | xargs kubectl delete pod --all-namespaces

13 从容器内拷贝文件到本地
kubectl cp <pod名称>:<容器内路径> <本地文件路径> -n <命名空间>
如: kubectl cp test-74fcb4fdff-fflbm:/logs/test.2024-06-20.1.log /root/test.2024-06-20.1.log -n prod

14 停止某个命名空间内的所有服务(通过修改副本数实现),不是删除,之后再启动,如命名空间为prod
停止:
kubectl scale deployment --replicas=0 --all -n prod
启动:
kubectl scale deployment --replicas=1 --all -n prod 

 

posted @ 2024-06-17 15:14  面向bug编程  阅读(4)  评论(0编辑  收藏  举报