kubernetes: Pods stuck in Termination state due to device mount path still mounted by other references
What happened?
I provisioned a stateful set with volumes. When I delete the pod, it might get stuck in Terminating state.
k describe po nginx-1
Name: nginx-1
Namespace: default
Priority: 0
Service Account: default
Node: kubermatic-v3-test-worker-7c4b8ff55f-njm2d/10.70.27.39
Start Time: Fri, 15 Dec 2023 07:59:56 +0100
Labels: app=nginx
controller-revision-hash=nginx-99cdf8db5
statefulset.kubernetes.io/pod-name=nginx-1
Annotations: <none>
Status: Terminating (lasts 77s)
Termination Grace Period: 30s
IP: 10.244.5.70
IPs:
IP: 10.244.5.70
Controlled By: StatefulSet/nginx
Containers:
nginx:
Container ID: containerd://563133485780a38e5313e61eca152af94482e6b660714f4351a5bbabc3bdaaad
Image: nginx
Image ID: docker.io/library/nginx@sha256:10d1f5b58f74683ad34eb29287e07dab1e90f10af243f151bb50aa5dbb4d62ee
Port: 80/TCP
Host Port: 0/TCP
State: Terminated
Reason: Completed
Exit Code: 0
Started: Fri, 15 Dec 2023 08:00:33 +0100
Finished: Fri, 15 Dec 2023 08:05:26 +0100
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/usr/share/nginx/html from nginx-vol (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-q5rt6 (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
nginx-vol:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: nginx-vol-nginx-1
ReadOnly: false
kube-api-access-q5rt6:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 5m52s default-scheduler 0/6 nodes are available: pod has unbound immediate PersistentVolumeClaims. preemption: 0/6 nodes are available: 6 Preemption is not helpful for scheduling..
Warning FailedScheduling 5m47s default-scheduler 0/6 nodes are available: pod has unbound immediate PersistentVolumeClaims. preemption: 0/6 nodes are available: 6 Preemption is not helpful for scheduling..
Normal Scheduled 5m44s default-scheduler Successfully assigned default/nginx-1 to kubermatic-v3-test-worker-7c4b8ff55f-njm2d
Normal SuccessfulAttachVolume 5m25s attachdetach-controller AttachVolume.Attach succeeded for volume "pvc-9941f76b-d039-483e-b726-49c4ab13c88a"
Normal Pulling 5m24s kubelet Pulling image "nginx"
Normal Pulled 5m7s kubelet Successfully pulled image "nginx" in 16.273349821s (16.273366021s including waiting)
Normal Created 5m7s kubelet Created container nginx
Normal Started 5m7s kubelet Started container nginx
Warning FailedMount 14s kubelet Unable to attach or mount volumes: unmounted volumes=[nginx-vol], unattached volumes=[], failed to process volumes=[]: timed out waiting for the condition
Normal Killing 14s kubelet Stopping container nginx
What did you expect to happen?
I expected the pod to successfully terminate. The mounts should be properly unmounted from the node when they are no longer needed. Errors should not continue to appear forever in logs.
How can we reproduce it (as minimally and precisely as possible)?
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nginx
namespace: default
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: nginx
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- mountPath: /usr/share/nginx/html
name: nginx-vol
volumeClaimTemplates:
- metadata:
name: nginx-vol
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Apply the manifest.
k apply -n default -f nginx-sts.yaml
Once the pod is running, delete it.
k delete po nginx-0
pod "nginx-0" deleted
k delete po nginx-1
pod "nginx-1" deleted
It may take a few attempts until one of the pods is stuck in terminating stage.
Anything else we need to know?
Relevant Kubelet logs:
Dec 15 09:11:40 kubermatic-v3-test-worker-7c4b8ff55f-njm2d kubelet[76364]: I1215 09:11:40.891134 76364 kubelet.go:2100] "Pod is terminated, but some volumes have not been cleaned up" pod="default/nginx-1" podUID=02efa2c6-bb93-4f09-8fd8-8318abf1d28f
Dec 15 09:11:40 kubermatic-v3-test-worker-7c4b8ff55f-njm2d kubelet[76364]: I1215 09:11:40.895356 76364 reconciler_common.go:286] "Starting operationExecutor.UnmountDevice for volume \"pvc-9941f76b-d039-483e-b726-49c4ab13c88a\" (UniqueName: \"kubernetes.io/csi/named-disk.csi.cloud-director.vmware.com^pvc-9941f76b-d039-483e-b726-49c4ab13c88a\") on node \"kubermatic-v3-test-worker-7c4b8ff55f-njm2d\" "
Dec 15 09:11:40 kubermatic-v3-test-worker-7c4b8ff55f-njm2d kubelet[76364]: I1215 09:11:40.895395 76364 reconciler_common.go:293] "operationExecutor.UnmountDevice started for volume \"pvc-9941f76b-d039-483e-b726-49c4ab13c88a\" (UniqueName: \"kubernetes.io/csi/named-disk.csi.cloud-director.vmware.com^pvc-9941f76b-d039-483e-b726-49c4ab13c88a\") on node \"kubermatic-v3-test-worker-7c4b8ff55f-njm2d\" "
Dec 15 09:11:40 kubermatic-v3-test-worker-7c4b8ff55f-njm2d kubelet[76364]: I1215 09:11:40.895625 76364 csi_attacher.go:261] kubernetes.io/csi: attacher.GetDeviceMountPath(&{nil &PersistentVolume{ObjectMeta:{pvc-9941f76b-d039-483e-b726-49c4ab13c88a 0e646ab8-764e-459d-aa62-2906e4cd7651 219624 0 2023-12-15 06:59:53 +0000 UTC <nil> <nil> map[] map[pv.kubernetes.io/provisioned-by:named-disk.csi.cloud-director.vmware.com] [] [kubernetes.io/pv-protection external-attacher/named-disk-csi-cloud-director-vmware-com] [{csi-provisioner Update v1 2023-12-15 06:59:53 +0000 UTC FieldsV1 {"f:metadata":{"f:annotations":{".":{},"f:pv.kubernetes.io/provisioned-by":{}}},"f:spec":{"f:accessModes":{},"f:capacity":{".":{},"f:storage":{}},"f:claimRef":{".":{},"f:apiVersion":{},"f:kind":{},"f:name":{},"f:namespace":{},"f:resourceVersion":{},"f:uid":{}},"f:csi":{".":{},"f:driver":{},"f:fsType":{},"f:volumeAttributes":{".":{},"f:busSubType":{},"f:busType":{},"f:diskID":{},"f:filesystem":{},"f:storage.kubernetes.io/csiProvisionerIdentity":{},"f:storageProfile":{}},"f:volumeHandle":{}},"f:persistentVolumeReclaimPolicy":{},"f:storageClassName":{},"f:volumeMode":{}}} } {kube-controller-manager Update v1 2023-12-15 06:59:53 +0000 UTC FieldsV1 {"f:status":{"f:phase":{}}} status} {csi-attacher Update v1 2023-12-15 06:59:56 +0000 UTC FieldsV1 {"f:metadata":{"f:finalizers":{"v:\"external-attacher/named-disk-csi-cloud-director-vmware-com\"":{}}}} }]},Spec:PersistentVolumeSpec{Capacity:ResourceList{storage: {{1073741824 0} {<nil>} 1Gi BinarySI},},PersistentVolumeSource:PersistentVolumeSource{GCEPersistentDisk:nil,AWSElasticBlockStore:nil,HostPath:nil,Glusterfs:nil,NFS:nil,RBD:nil,ISCSI:nil,Cinder:nil,CephFS:nil,FC:nil,Flocker:nil,FlexVolume:nil,AzureFile:nil,VsphereVolume:nil,Quobyte:nil,AzureDisk:nil,PhotonPersistentDisk:nil,PortworxVolume:nil,ScaleIO:nil,Local:nil,StorageOS:nil,CSI:&CSIPersistentVolumeSource{Driver:named-disk.csi.cloud-director.vmware.com,VolumeHandle:pvc-9941f76b-d039-483e-b726-49c4ab13c88a,ReadOnly:false,FSType:ext4,VolumeAttributes:map[string]string{busSubType: VirtualSCSI,busType: SCSI,diskID: urn:vcloud:disk:655992eb-ed2c-46ac-a97d-ffe20add356c,filesystem: ext4,storage.kubernetes.io/csiProvisionerIdentity: 1702567623209-8081-named-disk.csi.cloud-director.vmware.com,storageProfile: Intermediate,},ControllerPublishSecretRef:nil,NodeStageSecretRef:nil,NodePublishSecretRef:nil,ControllerExpandSecretRef:nil,NodeExpandSecretRef:nil,},},AccessModes:[ReadWriteOnce],ClaimRef:&ObjectReference{Kind:PersistentVolumeClaim,Namespace:default,Name:nginx-vol-nginx-1,UID:9941f76b-d039-483e-b726-49c4ab13c88a,APIVersion:v1,ResourceVersion:219566,FieldPath:,},PersistentVolumeReclaimPolicy:Delete,StorageClassName:vcd-named-disk,MountOptions:[],VolumeMode:*Filesystem,NodeAffinity:nil,},Status:PersistentVolumeStatus{Phase:Bound,Message:,Reason:,},} false false false})
Dec 15 09:11:40 kubermatic-v3-test-worker-7c4b8ff55f-njm2d kubelet[76364]: I1215 09:11:40.895651 76364 csi_attacher.go:266] attacher.GetDeviceMountPath succeeded, deviceMountPath: /var/lib/kubelet/plugins/kubernetes.io/csi/named-disk.csi.cloud-director.vmware.com/cb08f93cfef5ad623fd8de45938dfa01dadfc626396dcc242e0d3619c1216c09/globalmount
Dec 15 09:11:40 kubermatic-v3-test-worker-7c4b8ff55f-njm2d kubelet[76364]: E1215 09:11:40.896479 76364 nestedpendingoperations.go:348] Operation for "{volumeName:kubernetes.io/csi/named-disk.csi.cloud-director.vmware.com^pvc-9941f76b-d039-483e-b726-49c4ab13c88a podName: nodeName:}" failed. No retries permitted until 2023-12-15 09:13:42.896463003 +0000 UTC m=+7820.662192247 (durationBeforeRetry 2m2s). Error: GetDeviceMountRefs check failed for volume "pvc-9941f76b-d039-483e-b726-49c4ab13c88a" (UniqueName: "kubernetes.io/csi/named-disk.csi.cloud-director.vmware.com^pvc-9941f76b-d039-483e-b726-49c4ab13c88a") on node "kubermatic-v3-test-worker-7c4b8ff55f-njm2d" : the device mount path "/var/lib/kubelet/plugins/kubernetes.io/csi/named-disk.csi.cloud-director.vmware.com/cb08f93cfef5ad623fd8de45938dfa01dadfc626396dcc242e0d3619c1216c09/globalmount" is still mounted by other references [/var/lib/kubelet/pods/02efa2c6-bb93-4f09-8fd8-8318abf1d28f/volumes/kubernetes.io~csi/pvc-9941f76b-d039-483e-b726-49c4ab13c88a/mount]
There is one mount for the pvc:
root@kubermatic-v3-test-worker-7c4b8ff55f-njm2d:~# mount | grep pvc-9941f76b-d039-483e-b726-49c4ab13c88a
/dev/sdb on /var/lib/kubelet/pods/02efa2c6-bb93-4f09-8fd8-8318abf1d28f/volumes/kubernetes.io~csi/pvc-9941f76b-d039-483e-b726-49c4ab13c88a/mount type ext4 (rw,relatime)
And one for the plugin:
root@kubermatic-v3-test-worker-7c4b8ff55f-njm2d:~# mount | grep cb08f93cfef5ad623fd8de45938dfa01dadfc626396dcc242e0d3619c1216c09
/dev/sdb on /var/lib/kubelet/plugins/kubernetes.io/csi/named-disk.csi.cloud-director.vmware.com/cb08f93cfef5ad623fd8de45938dfa01dadfc626396dcc242e0d3619c1216c09/globalmount type ext4 (rw,relatime)
I can force delete the pod
k delete po nginx-1 --force
But this will leave behind a mount:
root@kubermatic-v3-test-worker-7c4b8ff55f-njm2d:~# mount | grep pvc-9941f76b-d039-483e-b726-49c4ab13c88a
/dev/sdb on /var/lib/kubelet/pods/02efa2c6-bb93-4f09-8fd8-8318abf1d28f/volumes/kubernetes.io~csi/pvc-9941f76b-d039-483e-b726-49c4ab13c88a/mount type ext4 (rw,relatime)
/dev/sdb on /var/lib/kubelet/pods/5dff85b0-167e-4877-a677-a9f9dd2857f4/volumes/kubernetes.io~csi/pvc-9941f76b-d039-483e-b726-49c4ab13c88a/mount type ext4 (rw,relatime)
The mounts on the node remain forever and the log message appears continually as the kubelet tries to unmount each volume repeatedly.
Dec 15 09:21:19 kubermatic-v3-test-worker-7c4b8ff55f-njm2d kubelet[76364]: I1215 09:21:19.292183 76364 kubelet.go:2100] "Pod is terminated, but some volumes have not been cleaned up" pod="default/nginx-1" podUID=02efa2c6-bb93-4f09-8fd8-8318abf1d28f
Dec 15 09:21:19 kubermatic-v3-test-worker-7c4b8ff55f-njm2d kubelet[76364]: I1215 09:21:19.391881 76364 kubelet_volumes.go:93] "Pod found, but volumes are still mounted on disk" podUID=02efa2c6-bb93-4f09-8fd8-8318abf1d28f paths=[/var/lib/kubelet/pods/02efa2c6-bb93-4f09-8fd8-8318abf1d28f/volumes/kubernetes.io~csi/pvc-9941f76b-d039-483e-b726-49c4ab13c88a/mount]
If I drain the node or try to start the pod some other way on another node it will be stuck in ContainerCreating state due to Multi-Attach error
k describe po nginx-1
Name: nginx-1
Namespace: default
Priority: 0
Service Account: default
Node: kubermatic-v3-test-worker-7c4b8ff55f-54s8m/10.70.27.38
Start Time: Fri, 15 Dec 2023 10:38:39 +0100
Labels: app=nginx
controller-revision-hash=nginx-99cdf8db5
statefulset.kubernetes.io/pod-name=nginx-1
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: StatefulSet/nginx
Containers:
nginx:
Container ID:
Image: nginx
Image ID:
Port: 80/TCP
Host Port: 0/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/usr/share/nginx/html from nginx-vol (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9hsb8 (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
nginx-vol:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: nginx-vol-nginx-1
ReadOnly: false
kube-api-access-9hsb8:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m22s default-scheduler Successfully assigned default/nginx-1 to kubermatic-v3-test-worker-7c4b8ff55f-54s8m
Warning FailedAttachVolume 2m23s attachdetach-controller Multi-Attach error for volume "pvc-9941f76b-d039-483e-b726-49c4ab13c88a" Volume is already exclusively attached to one node and can't be attached to another
Warning FailedMount 20s kubelet Unable to attach or mount volumes: unmounted volumes=[nginx-vol], unattached volumes=[nginx-vol], failed to process volumes=[]: timed out waiting for the condition
Only when I manually unmount the stuck mount path
root@kubermatic-v3-test-worker-7c4b8ff55f-njm2d:~# mount | grep pvc-9941f76b-d039-483e-b726-49c4ab13c88a
/dev/sdb on /var/lib/kubelet/pods/02efa2c6-bb93-4f09-8fd8-8318abf1d28f/volumes/kubernetes.io~csi/pvc-9941f76b-d039-483e-b726-49c4ab13c88a/mount type ext4 (rw,relatime)
root@kubermatic-v3-test-worker-7c4b8ff55f-njm2d:~# umount /var/lib/kubelet/pods/02efa2c6-bb93-4f09-8fd8-8318abf1d28f/volumes/kubernetes.io~csi/pvc-9941f76b-d039-483e-b726-49c4ab13c88a/mount
the pod will be able to start on another node.
Here is the pvc
k get pvc nginx-vol-nginx-1 -oyaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
pv.kubernetes.io/bind-completed: "yes"
pv.kubernetes.io/bound-by-controller: "yes"
volume.beta.kubernetes.io/storage-provisioner: named-disk.csi.cloud-director.vmware.com
volume.kubernetes.io/storage-provisioner: named-disk.csi.cloud-director.vmware.com
creationTimestamp: "2023-12-15T06:59:48Z"
finalizers:
- kubernetes.io/pvc-protection
labels:
app: nginx
name: nginx-vol-nginx-1
namespace: default
resourceVersion: "219602"
uid: 9941f76b-d039-483e-b726-49c4ab13c88a
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: vcd-named-disk
volumeMode: Filesystem
volumeName: pvc-9941f76b-d039-483e-b726-49c4ab13c88a
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
And the pv
k get pv pvc-9941f76b-d039-483e-b726-49c4ab13c88a -oyaml
apiVersion: v1
kind: PersistentVolume
metadata:
annotations:
pv.kubernetes.io/provisioned-by: named-disk.csi.cloud-director.vmware.com
creationTimestamp: "2023-12-15T06:59:53Z"
finalizers:
- kubernetes.io/pv-protection
- external-attacher/named-disk-csi-cloud-director-vmware-com
name: pvc-9941f76b-d039-483e-b726-49c4ab13c88a
resourceVersion: "219624"
uid: 0e646ab8-764e-459d-aa62-2906e4cd7651
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
claimRef:
apiVersion: v1
kind: PersistentVolumeClaim
name: nginx-vol-nginx-1
namespace: default
resourceVersion: "219566"
uid: 9941f76b-d039-483e-b726-49c4ab13c88a
csi:
driver: named-disk.csi.cloud-director.vmware.com
fsType: ext4
volumeAttributes:
busSubType: VirtualSCSI
busType: SCSI
diskID: urn:vcloud:disk:655992eb-ed2c-46ac-a97d-ffe20add356c
filesystem: ext4
storage.kubernetes.io/csiProvisionerIdentity: 1702567623209-8081-named-disk.csi.cloud-director.vmware.com
storageProfile: Intermediate
volumeHandle: pvc-9941f76b-d039-483e-b726-49c4ab13c88a
persistentVolumeReclaimPolicy: Delete
storageClassName: vcd-named-disk
volumeMode: Filesystem
status:
phase: Bound
Kubernetes version
Client Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.10", GitCommit:"b8609d4dd75c5d6fba4a5eaa63a5507cb39a6e99", GitTreeState:"clean", BuildDate:"2023-10-18T11:44:31Z", GoVersion:"go1.20.10", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.7", GitCommit:"07a61d861519c45ef5c89bc22dda289328f29343", GitTreeState:"clean", BuildDate:"2023-10-18T11:33:23Z", GoVersion:"go1.20.10", Compiler:"gc", Platform:"linux/amd64"}
Cloud provider
OS version
cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
uname -a
Linux kubermatic-v3-test-worker-7c4b8ff55f-njm2d 5.15.0-72-generic #79-Ubuntu SMP Wed Apr 19 08:22:18 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Install tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, …) and versions (if applicable)
csi-vcd-controllerplugin version: image: registry.k8s.io/sig-storage/csi-attacher:v3.2.1 image: registry.k8s.io/sig-storage/csi-provisioner:v2.2.2 image: projects.registry.vmware.com/vmware-cloud-director/cloud-director-named-disk-csi-driver:1.4.0
csi-vcd-nodeplugin version: image: registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.2.0 image: projects.registry.vmware.com/vmware-cloud-director/cloud-director-named-disk-csi-driver:1.4.0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 30 (14 by maintainers)
I am sorry, I did not see that this was @vitality411 's issue. I will tackle this in the above-mentioned CSI repo.
Thanks for your informations. It’s a sad story. After a deep looking, I don’t know why the following code doesn’t work.
https://github.com/vmware/cloud-director-named-disk-csi-driver/blob/1.4.0/vendor/github.com/akutz/gofsutil/gofsutil_mount_unix.go#L70
NodePublishVolume is only called once, so it’s impossible for kubelet to make unmounted target path become re-mounted again.
😭 I need help from others.
Friendly ping @ymo24 @arunmk
cc @xing-yang @jsafrane