Home > front end >  The data still there after PV/PVC deleted in Kubernetes
The data still there after PV/PVC deleted in Kubernetes

Time:12-30

I am trying to create a single pod postgres deployment on my local machine, I use PVC / PV for the data store.

At beginning I started postgres in v15, and later I changed to v14, but it complains: The data directory was initialized by PostgreSQL version 15, which is not compatible with this version 14.6. even after I delete everything and start again. Do you guys know what's going on?

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 1
  selector:
    matchLabels:
      name: postgres
  template:
    metadata:
      labels:
        name: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:14-alpine
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgredb
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: postgres-pvc
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: postgres-pv
spec:
  storageClassName: manual
  capacity:
    storage: 300Mi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Delete
  hostPath:
    path: "/mnt/data"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: postgres-pvc
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 2

CodePudding user response:

Do you guys know what's going on?

You are using hostPath volume, so you are just using a local directory on your local machine. And there seem to be some files in this directory.

When using PersistentVolumeClaims in a cloud environment, it is common to use volumes that are provisioned from a cloud system, where you get a new volume for each PVC.

CodePudding user response:

My context is using kind on macbook.

The PV is physically on the kind container. After delete the PV, we need to manually delete the folder. The following command will delete the physical folder.

docker exec -it $(docker ps -a | grep kind-control-plane | awk '{print $1}')  rm -rf /your-hostpath
  • Related