摘要:在没有 Docker 的环境里,容器由containerd管理。在 Kubernetes 场景下,容器一般位于 k8s.io namespace 下。本文档总结常用命令与操作方法,便于日常运维。
在没有 Docker 的环境里,容器由 containerd 管理。
在 Kubernetes 场景下,容器一般位于 k8s.io namespace 下。
本文档总结常用命令与操作方法,便于日常运维。
列出运行中的任务:
sudo ctr -n k8s.io t lssudo ctr -n k8s.io tasks attach或者查看宿主机日志文件:
sudo tail -f /var/log/containers/sudo ctr -n k8s.io tasks exec -t --exec-id debug$$/bin/sh⚠️ --exec-id 必须唯一,可随便取,如 debug$$。
sudo crictl exec -it/bin/sh⚠️ 注意:
按镜像名过滤:
sudo ctr -n k8s.io c ls | grep nginx按 Pod 名过滤:
sudo ctr -n k8s.io c ls | grep myapp-podfunction cexec { name=$1 id=$(sudo ctr -n k8s.io c ls | grep $name | awk '{print $1}' | head -n1) if [ -z "$id" ]; then echo "Container not found!" return 1 fi sudo ctr -n k8s.io t exec -t --exec-id shell$$ $id /bin/sh}用法:
function clogs { name=$1 logfile=$(ls /var/log/containers | grep $name | head -n1) if [ -z "$logfile" ]; then echo "Log file not found!" return 1 fi sudo tail -f /var/log/containers/$logfile}用法:
来源:linux运维菜
免责声明:本站系转载,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请在30日内与本站联系,我们将在第一时间删除内容!