'Helm + K8S - access the persistent volume

I am using K8S with Helm 3.

I am also using MYSQL 5.7 database.

I created MYSQL pod, whenever the database persists (it is created after first time the pod is created, and even the pod is down and up again, the data won't be lost).

I am using PersistentVolume and PersistentVolumeClaim.

Here are the YAML files:

Mysql pod:

apiVersion: v1
kind: Pod
metadata:
  name: myproject-db
  namespace: {{ .Release.Namespace }}
  labels:
    name: myproject-db
    app: myproject-db
spec:
  hostname: myproject-db
  subdomain: {{ include "k8s.db.subdomain" . }}
  containers:
    - name: myproject-db
      image: mysql:5.7
      imagePullPolicy: IfNotPresent
      env:
        MYSQL_DATABASE: test
        MYSQL_ROOT_PASSWORD: 12345
      ports:
        - name: mysql
          protocol: TCP
          containerPort: 3306
      resources: 
        requests: 
          cpu: 200m
          memory: 500Mi
        limits:
          cpu: 500m
          memory: 600Mi
      volumeMounts:
        - name: mysql-persistence-storage
          mountPath: /var/lib/mysql
  volumes:
    - name: mysql-persistence-storage
      persistentVolumeClaim:
        claimName: mysql-pvc

Persistent Volume:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
  labels:
    type: local
    name: mysql-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/mysql"

Persistent Volume Claim:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  volumeMode: Filesystem
  volumeName: mysql-pv

after running:

Helm install myproject myproject/

The database is created, and can be used.

If I add records and stop and remove the database pod - there is no loss of db records, even I restart the pod by running: helm delete myproject and by running: helm install myproject myproject/ again.

I see that the db data is kept when the MYSQL pod is restarted.

How can I access the data of mysql?

I see no files on /var/lib/mysql neither on /data/mysql - how can I access those two paths?

Also - how can I delete permanently the data? (can I delete the files themselves or just by kubectl commands?)

Thanks.



Solution 1:[1]

You are using a hostPath volume, thus the persistence is directly on your node. You can ssh to your node and delete those files.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Root -