使用describe命令进行Kubernetes pod错误排查
我有一个pod名叫another,用kubectl create创建后发现过了29分钟,状态还是处于ContainerCreating阶段。
使用kubectl describe命令检查:
从错误消息发现是因为这个pod attach volume失败:
FailedAttachVolume 2m1s (x22 over 31m) attachdetach-controller AttachVolume.Attach failed for volume "pvc-c4d41f5c-e7ed-11e8-8726-fe6d42bf075f" : googleapi: Error 400: RESOURCE_IN_USE_BY_ANOTHER_RESOURCE - The disk resource 'projects/sap-pi-coo-acdc-dev/zones/europe-west1-b/disks/shoot--k8s-train--shac-pvc-c4d41f5c-e7ed-11e8-8726-fe6d42bf075f' is already being used by 'projects/sap-pi-coo-acdc-dev/zones/europe-west1-b/instances/shoot--k8s-train--shacw46-worker-prvfv-z1-7844dc6744-ghd5m'
Warning FailedMount 31s (x14 over 29m) kubelet, shoot--k8s-train--shacw46-worker-prvfv-z1-7844dc6744-hhrmd Unable to mount volumes for pod "another_part-0110(13f15fa4-e819-11e8-8726-fe6d42bf075f)": timeout expired waiting for volumes to attach or mount for pod "part-0110"/"another". list of unmounted volumes=[content-storage]. list of unattached volumes=[content-storage default-token-6z5sk]
查看这个pod的yaml文件,果然发现有一个persistent volume的claim:
用命令kubectl get pv, 发现当前所有的persistent volume都被占用了(BOUND状态):
解决方案有很多种,处于测试目的,我只是简单地将另一个同样声明了nginx-pvc作为PersistentVolumeClaim的pod删除,然后这个名为another的pod状态就很快变成Running了:
从describe命令生成的日志里也能清楚的观察到这个成功mount volume的事件:
Normal SuccessfulAttachVolume 84s attachdetach-controller AttachVolume.Attach succeeded for volume "pvc-c4d41f5c-e7ed-11e8-8726-fe6d42bf075f"
要获取更多Jerry的原创文章,请关注公众号"汪子熙":