Kubernetes常用运维命令总结
原创
©著作权归作者所有:来自51CTO博客作者lemon时雨的原创作品,如需转载,请与作者联系,否则将追究法律责任
1.强制删除 Terminating 状态的pod
有些pod在Terminating状态下无法清除,需要手动使用命令删除
[root@k8s-master coredns]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-7bb7cd8db5-5c7z9 1/1 Terminating 0 70m
nginx-7bb7cd8db5-t24hf 1/1 Running 0 57m
在常规删除命令后增加--grace-period=0和--force
参数,即可强制删除pod
[root@k8s-master coredns]# kubectl delete pod nginx-7bb7cd8db5-5c7z9 --grace-period=0 --force
warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "nginx-7bb7cd8db5-5c7z9" force deleted
强制删除成功
[root@k8s-master coredns]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-7bb7cd8db5-t24hf 1/1 Running 0 60m
注:这里只是清除了etcd中关于该pod的信息,实际上pod可能未被完全清除
2.快速修改deployment下指定容器的image
kubectl -n 命名空间 set image deployment/指定deployment的名称 指定容器的名称=镜像全路径
kubectl -n fygs-prd set image deployment/matrix matrix=harbor.cfuture.shop/cfuture/matrix:版本号
3.容器镜像通过containerd导入k8s集群
#导入镜像
ctr -n k8s.io i import xxx.tar
#修改镜像tag
ctr -n k8s.io i tag cfuture-harbor-registry-vpc.cn-hangzhou.cr.aliyuncs.com/c2f/matrix:版本号 harbor.cfuture.shop/cfuture/matrix:版本号
注:如果是跨平台导入tar包(比如从mac系统上制作的tar包导入到linux服务器中),建议在原平台压缩成tgz包,然后到目标平台解压后再导入解压后的tar包,否则可能会因为tar包格式不兼容而导致导入失败
4.容器镜像通过containerd推送私有仓库
ctr -n k8s.io i push 镜像全路径 --plain-http --user 用户名:密码
注:由于ctr推送镜像,默认使用https协议,因此需要使用--plain-http
参数,在推送时使用http协议