Docker Desktop for Windows - Unable to create a persistent volume on local hard drive

5/15/2020

I want to create persistent volume for postgres kubernetes pod on windows 10 (C:\Postrges)

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:

  name: localstorage

provisioner: docker.io/hostpath
volumeBindingMode: Immediate
reclaimPolicy: Delete
allowVolumeExpansion: True

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: database-persistent-volume-claim
spec:
  storageClassName: localstorage
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

---

# How do we want it implemented
apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-storage
spec:
  storageClassName: localstorage
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete  
  hostPath:
    path: "/C/postgres"
    type: DirectoryOrCreate





$ kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM                                      STORAGECLASS   REASON   AGE  
local-storage                              2Gi        RWO            Delete           Available                                              localstorage            4m14s
pvc-7e1d810f-1114-4b7c-9160-2b07830c682f   2Gi        RWO            Delete           Bound       default/database-persistent-volume-claim   localstorage            4m14s

$ kubectl get pvc
NAME                               STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
database-persistent-volume-claim   Bound    pvc-7e1d810f-1114-4b7c-9160-2b07830c682f   2Gi        RWO            localstorage   5m36s

No events for PV, for PVC it shows "waiting for a volume to be created, either by external provisioner"

kubectl describe pvc
Name:          database-persistent-volume-claim
Namespace:     default
StorageClass:  localstorage
Status:        Bound
Volume:        pvc-7e1d810f-1114-4b7c-9160-2b07830c682f
Labels:        <none>
Annotations:   pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
               volume.beta.kubernetes.io/storage-provisioner: docker.io/hostpath
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      2Gi
Access Modes:  RWO
VolumeMode:    Filesystem
Mounted By:    <none>
Events:
  Type    Reason                 Age    From                                                                         Message
  ----    ------                 ----   ----                                                                         -------
  Normal  ExternalProvisioning   7m24s  persistentvolume-controller                                                  waiting for a volume to be created, either by external provisioner "docker.io/hostpath" or manually created by system administrator
  Normal  Provisioning           7m24s  docker.io/hostpath_storage-provisioner_4bfa0399-b72d-4e03-ae9d-70ee4d8a7c33  External provisioner is provisioning volume for claim "default/database-persistent-volume-claim"
  Normal  ProvisioningSucceeded  7m24s  docker.io/hostpath_storage-provisioner_4bfa0399-b72d-4e03-ae9d-70ee4d8a7c33  Successfully provisioned volume pvc-7e1d810f-1114-4b7c-9160-2b07830c682f

But in windows explorer i can't see postgres folder on C drive

PVC is assigned to postgres pod

 volumes:
        - name: postgres-storage
          persistentVolumeClaim:
           claimName: database-persistent-volume-claim
      containers:
        - name: postgres
          image: postgres
          ports:
            - containerPort: 5432
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              subPath: postgres
              name: postgres-storage

Pod has no any errors, ran CMD as Administrator before executing kubectl apply, same configuration works without issues on Linux. Any thougts ?

enter image description here

-- overflowed
docker
kubernetes

1 Answer

5/15/2020

In fact, everything is OK, Docker Desktop doesn't map Windows local storage but reclaim space on VM created when Docker Desktop is installed.

This VM can be accessed as described in this post

kubectl get pvc
NAME                               STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
database-persistent-volume-claim   Bound    pvc-ceb8dfa1-37ca-48fe-b4bc-cc642faac6c4   2Gi        RWO            localstorage   33m

Browsing Docker desktop VM:

ls /var/lib/k8s-pvs/database-persistent-volume-claim/pvc-ceb8dfa1-37ca-48fe-b4bc-cc642faac6c4/postgres
PG_VERSION            pg_hba.conf           pg_replslot           pg_subtrans           postgresql.auto.conf
base                  pg_ident.conf         pg_serial             pg_tblspc             postgresql.conf
global                pg_logical            pg_snapshots          pg_twophase           postmaster.opts
pg_commit_ts          pg_multixact          pg_stat               pg_wal
pg_dynshmem           pg_notify             pg_stat_tmp           pg_xact

When postgres deployment is deleted, database files remain

enter image description here

-- overflowed
Source: StackOverflow