k8s 记录一次longhorn重启后容器pvc挂载不上的问题

发布时间 2023-04-13 10:23:23作者: liwenchao1995

k8s 记录一次longhorn重启后容器pvc挂载不上的问题

起因及报错

k8s上部署了longhorn,数据在三个节点上分别都有备份,重启服务器后发现一些statefulset的容器启动失败报错

//有好几个statefulset的容器报错,下面是其中2个
//nacos报错
AttachVolume.Attach failed for volume "pvc-cc910a66-75b0-475a-84a7-bb6418c4e04a" : rpc error: code = DeadlineExceeded desc = volume pvc-cc910a66-75b0-475a-84a7-bb6418c4e04a failed to attach to node idc-general-k8s-29 
//另一个容器报错
Unable to attach or mount volumes: unmounted volumes=[redis-data], unattached volumes=[start-scripts health redis-data config redis-tmp-conf tmp redis-standalone-token-r7tpv]: timed out waiting for the condition

解决步骤

这个错误信息表明 Kubernetes 无法将某些容器的挂载卷(Volume)附加到节点(Node)上,可能是由于 Kubernetes 调度程序无法在指定的时间内完成挂载操作所致。

  • 检查节点状态:使用 kubectl get nodes 命令检查节点的状态,确保该节点处于 "Ready" 状态。

  • 检查 Longhorn 状态:使用 kubectl get pods -n longhorn-system 命令检查 Longhorn 的各个组件的状态,确保 Longhorn 正常运行。

  • 检查 PVC 状态:使用 kubectl get pvc 命令检查 PVC 的状态,确保 PVC 处于 "Bound" 状态。

  • 检查 PV 状态:使用 kubectl get pv 命令检查 PV 的状态,确保 PV 处于 "Bound" 状态,并且已经正确绑定到 PVC。

  • 检查相关的 Pod:使用 kubectl get pods 命令检查相关的 Pod 的状态,确保它们已经正确挂载了 PVC。

如果上述步骤都没有解决问题,您可以尝试删除相关的 Pod 和 PVC,然后重新创建它们。另外,您也可以尝试手动挂载 PVC 到节点上,以验证 Longhorn 存储插件是否正常工作。

本次问题处理

我是检查到第2步,kubectl get pods -n longhorn-system