k8s常用操作

 

namespace相关

  • 创建namespace

kubectl create namespace test

 


 创建/删除

  • 根据yml配置创建pod、server等

kubectl create -f xxx.yml
  • 根据yml配置删除pod、server等 

kubectl delete -f  xxx.yml  

 


查询

  • 查看集群中namespace为default下的pod

kubectl get pod
  • 查看指定namespace的pod

kubectl get pod -n my-namespace
  • 查看集群中namespace为default下的svc

kubectl get svc
  • 查看集群中所有namespace下的svc

kubectl get svc --all-namespaces
  • 查看集群中namespace为default下deployment

kubectl get deployment
  • 获取pod的描述信息

kubectl describe pod grafana-74f77995c-qdf9t
  • 删除pod

注:当有deployment时,k8s会保证集群中pod的数量符合定义时规定的数量,所以这里可能会出现删除又新建pod

kubectl delete pod  grafana-74f77995c-wqsnb    
  • 删除deployment

kubectl delete deployment grafana   
  • 强制重启pod,实质就是读出原有pod的yaml文件,然后替换

kubectl get pod fortio-7f58f6f75f-wc96j  -n tests -o yaml | kubectl replace --force -f -
  • 查看pod部署在node的地址

kubectl get pod -n tests -o wide
  • node节点的信息

kubectl describe nodes 127-0-0-42

 


批量操作

 

  • 批量删除svc

kubectl get svc -n my-namespace| awk '{print $1}'|xargs kubectl delete svc -n my-namespace

 

  • 批量删除pod

kubectl get pod -n my-namespace| awk '{print $1}'|xargs kubectl delete pod -n my-namespace

 其他操作

  • 进入容器

kubectl exec -it tester-849869c9fd-xhvdz  -n dapr-system -- bash
  • 查看指定pod的日志

 -c指定哪个容器 -f实时滚动

kubectl logs -f grafana-74f77995c-wqsnb  -n default        
kubectl logs -f app-7f58f6f75f-x76vf  -n tests -c server

 

 


 限制

  • 资源限制类型

kubectl  describe  pod fortio-7f58f6f75f-wc96j  -n tests|grep QoS  
  • 获取pod的cpu、Memory限制

kubectl describe node | grep testapp-5d7b6b6fc7-brs6z -B3

 


更新

更新容器的镜像

kubectl patch pod grafana-65f7ccd56f-c97wf -n dapr-system -p '{"spec":{"containers":[{"name":"grafana","image":"grafana/grafana:latest"}]}}'


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值