"VolumeFailedDelete" error in the k8s cluster provided by docker-for-windows

6/26/2019

I created a PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 8Gi

Since the PVC doesn't specify a storage class, it will use the default storage class of the cluster. For my cluster, it is hostpath:

 $ kubectl get sc

    NAME                 PROVISIONER          AGE
    hostpath (default)   docker.io/hostpath   47d

The ReclaimPolicy of this sc is Delete. But still, when i remove the pvc, pv is not deleted. There is an error deleting the volume:

$ kubectl describe pv

Name:            pvc-eb128563-97fa-11e9-8f00-00155d380109
Labels:          <none>
Annotations:     pv.kubernetes.io/provisioned-by=docker.io/hostpath
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    hostpath
Status:          Released
Claim:           default/myclaim
Reclaim Policy:  Delete
Access Modes:    RWO
Capacity:        8Gi
Node Affinity:   <none>
Message:
Source:
    Type:          HostPath (bare host directory volume)
    Path:          /host_mnt/c/Users/Anjana/.docker/Volumes/myclaim/pvc-eb128563-97fa-11e9-8f00-00155d380109
    HostPathType:
Events:
  Type     Reason              Age              From                                                                     Message
  ----     ------              ----             ----                                                                     -------
  Warning  VolumeFailedDelete  7s (x7 over 1m)  docker.io/hostpath DESKTOP-SRHMA82 87a9c372-97ca-11e9-bdd7-00155d38010b  persistent volume path is not prefixed by C:\Users\Anjana\.docker\Volumes

Why this happens? Can anyone please help me?

-- AnjanaDyna
docker
docker-for-windows
kubernetes
volume

2 Answers

7/16/2019

I've got the same issue.

Warning VolumeFailedDelete persistentvolume/pvc-888e0eed-a795-11e9-8838-00155d9d5106 persistent volume path is not prefixed by C:\Users\user.docker\Volumes

Volume is created via PVC, hostPath is (automatically) set to that /host_mnt/c/Users/user/.docker/Volumes/myclaim/pvc-eb128563-97fa-11e9-8f00-00155d380109

-- Vojtěch Liška
Source: StackOverflow

6/27/2019

Basing at the error you receive

persistent volume path is not prefixed by C:\Users\Anjana.docker\Volumes

And looking through the documentation:

pathPrefix is the path prefix that the host volume must match. It does not support *. Trailing slashes are trimmed when validating the path prefix with a host path. Examples: /foo would allow /foo, /foo/ and /foo/bar /foo would not allow /food or /etc/foo

You should check if the path is configured properly in your pv yaml spec.

  hostPath:
    path: 

EDIT: Also Finalizers: [kubernetes.io/pv-protection] It means that your PV is protected. You can change that by setting finalizers to null

Let me know if that helped.

-- OhHiMark
Source: StackOverflow