我试图在本地机器上创建一个pod postgres部署,我使用PVC/PV作为数据存储。
一开始我开始在v15的postgres,后来我改变到v14,但它抱怨:The data directory was initialized by PostgreSQL version 15, which is not compatible with this version 14.6.
,即使我删除了一切,重新开始。你们知道发生了什么事吗?
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
你们知道发生了什么吗?
您正在使用hostPath卷,所以您只是在本地机器上使用本地目录。这个目录里好像有一些文件。
在云环境中使用persistentvolumeclclaims时,通常使用从云系统供应的卷,其中每个PVC获得一个新卷。
我的上下文在macbook上使用kind
PV物理上位于kind
容器上。删除PV后,我们需要手动删除文件夹。以下命令将删除物理文件夹。
docker exec -it $(docker ps -a | grep kind-control-plane | awk '{print $1}') rm -rf /your-hostpath
我尝试了保留策略为Recycle,为我工作。
persistentVolumeReclaimPolicy:回收
在Recycle的情况下,主机文件夹内的数据被完全删除。
例如:rm -rf/mnt/data/*
裁判:https://kubernetes.io/docs/concepts/storage/persistent-volumes/reclaim-policy