Contents

Solved kubelet E1103 Orphaned Pod

Contents

今年在公司一个小项目上部署了 k8s,学以致用。

这两天检查 kubelet 日志的里面发现有这样的错误日志:

1
Nov  3 18:12:26 k8s-02 kubelet: E1103 18:12:26.572010    1324 kubelet_volumes.go:154] orphaned pod "930d1c27-a975-4de5-9e8f-6e74d42d39e5" found, but volume paths are still present on disk : There were a total of 82 errors similar to this. Turn up verbosity to see them.

经查,使用 kubectl delete --force 删除 pod 或者系统异常关闭都会导致该问题出现,即:pod异常退出均有可能出现上面的报错。

Solved

要解决该问题,其实很简单,只需要删除 /var/lib/kubelet 目录下,名为报错ID的目录就行,可以使用下面的命令批量删除:

1
2
3
# 建议切换到 kublet目录再执行删除,不然可能删除整个 /var/lib/kubelet 导致严重的后果
cd /var/lib/kubelet
for x in $(seq 1 100);do pod_id=$(tail -n 1 /var/log/messages | awk -F '"' '/orphaned pod/ {print $2}');[[ "x$pod_id" != "x" ]] && rm -rf $pod_id && echo "rm ${pod_id}" ;sleep 2;done

在删除的过程中,可能会出现 Device or resource busy 导致删除失败,比如:

1
rm: cannot remove ‘116f7eee-375b-433c-99c4-bb6d106040db/volume-subpaths/nas-377e44fd-8ed0-4c06-aebb-9b97a49081d8/prometheus/2’: Device or resource busy

可能是该目录仍然挂载在系统中:

https://statics.lshell.com//images/image-20211103182118206.png

这时需要 umount 该目录

1
2
3
# Example
umount /var/lib/kubelet/pods/5c6433b9-fd3c-449d-81f9-a4893031a428/volume-subpaths/nas-82ddd304-91a5-4b59-9470-902872216a20/prometheus/2
umount /var/lib/kubelet/pods/4dcdbe69-50b7-48f6-91e1-6ee94ac67063/volume-subpaths/nas-377e44fd-8ed0-4c06-aebb-9b97a49081d8/prometheus/2

然后继续执行上面的删除命令即可

Refer