Search code examples
kubernetesdocker-desktoppersistent-volumes

Clear persistent volume from a Kubernetes cluster running on Docker Desktop


I'm running a MySQL image in my one-node cluster for local testing purposes only.

I would like to be able to delete the database when needed to have the image build a new database from scratch, but I can't seem to find where or how I can do that easily.

I am on Windows, using Docker Desktop to manage my Docker images and Kubernetes cluster with WSL2. The pod uses a persistent volume/claim which can be seen below.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 3Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/var/MySQLTemp"
    type: DirectoryOrCreate
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi

The volume part of my deployment looks like:

        volumeMounts:
        - name: mysql-persistent
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent
        persistentVolumeClaim:
          claimName: mysql-pv-claim

Is there a command I can use to either see where this database is stored on my Windows or WSL2 machine so I can delete it manually, or delete it from the command line through docker or kubectl?


Solution

  • For anyone looking in the future for this solution, and doesn't want to dredge through deep github discussions, my solution was this:

    Change hostPath: to local: when defining the path. hostPath is apparently for if your kubernetes node providers have external persistent disks, like GCE or AWS.

    Second, the path pointing to the symlink to your local machine from Docker desktop can apparently be found at /run/desktop/mnt/host/c for your c drive. I set my path to /run/desktop/mnt/host/c/MySQLTemp and created a MySQLTemp file in the root of my C drive, and it works.

    Third, a local: path definition requires a nodeAffinity. You can tell it to use Docker Desktop like this:

    spec:
      nodeAffinity:
        required:
          nodeSelectorTerms:
            - matchExpressions:
                - key: kubernetes.io/hostname
                  operator: In
                  values:
                    - docker-desktop