3

I recently started using PersistentVolumes and PersistenVolumeClaims for persistent storage in my container.

My end goal is to make sure that a file in a specific folder (let's call it data) on the container survives any restart. The implementation is:

  1. Creation of the PersistentVolume
  2. Creation of the PersistentVolumeClaim that automatically binds to the PV thanks to a Storage Class
  3. Creation of a simple deployment that pulls a single image from a remote repository

The deployment starts correctly. I am able to connect to the only container and create a file in data

If i delete and recreate the deployment, i can see that it pulls the image, recreates the pod and the container, and by reconnecting to the container i see the file previously created in the folder data. This is expected behaviour.

If i restart my PC, I can see the deployment automatically starting the pods, and both the PV and PVC are still there and working.

However, if I access the data folder, i can't see the previously created file. So, my questions are:

1. Are PersistentVolumes meant to persist even after a hard machine restart?

2. If so, how can I achieve this?

I understand that I am missing a lot of theory on how Kubernetes works, but the official documentation doesn't cover this, and I couldn't find any useful information online. If you need any YAML file of the entities just tell me. Thanks.

EDIT:

Yaml config of both the PV and PVC:

apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: vl0001
    spec:
      storageClassName: my-sc
      capacity:
        storage: 2Gi
      accessModes:
        - ReadWriteOnce
      local:
        path: /mnt
      nodeAffinity:
        required:
          nodeSelectorTerms:
          - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
              - node0001

PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc0001
spec:
  storageClassName: my-sc
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
Axel
  • 311
  • 2
  • 9
  • How are you testing Kubernetes? You mentioned your computer, does that mean you are using minikube? – AndD Mar 16 '22 at 13:15
  • @AndD no, I'm not using minikube. I only Installed Docker desktop and then enabled Kubernetes by the settings page – Axel Mar 16 '22 at 13:22
  • What kind of persistent volumes are you trying to create? Host path? Can you post the yaml definition? – AndD Mar 17 '22 at 08:40
  • added both PV and PVC YAML to the question – Axel Mar 17 '22 at 09:01
  • I'm unable to test Docker Desktop but searching around I found this which mees related: https://github.com/docker/for-win/issues/7023 – AndD Mar 17 '22 at 09:56
  • That's exactly the problem I am facing. Looks like it's on the Docker side but they did't event address the issue... – Axel Mar 18 '22 at 15:45
  • @Axel you solved? – stecog Nov 08 '22 at 12:44
  • Not yet, but I haven't tried in a while. I'll test this again on the latest Docker Desktop version asap and update this post. – Axel Nov 09 '22 at 07:47

0 Answers0