I have the following configuration
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pvc-v1 # Sets name of PVC
labels:
app: postgres
spec:
storageClassName: do-block-storage
accessModes:
- ReadWriteOnce # Sets read and write access
resources:
requests:
storage: 10Gi # Sets volume size
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgis/postgis # Sets Image
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 5432 # Exposes container port
envFrom:
- configMapRef:
name: postgres-cfg
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgredb
volumes:
- name: postgredb
persistentVolumeClaim:
claimName: postgres-pvc-v1
---
but in the pod log I have the following error
Data page checksums are disabled.
initdb: error: directory "/var/lib/postgresql/data" exists but is not empty
initdb: detail: It contains a lost+found directory, perhaps due to it being a mount point.
initdb: hint: Using a mount point directly as the data directory is not recommended.
Create a subdirectory under the mount point.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
To resolve this issue, you can create a subdirectory under the mount point and use that as the PostgreSQL data directory. Modify your Deployment configuration to include the
subPath
field for thevolumeMounts
. Here’s an updated configuration:For more info on
subPath
, you can check out the docs here:https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath
With this change, PostgreSQL will store its data in the
pgdata
subdirectory of the mounted volume, avoiding the issue with thelost+found
directory.However, on another note, I would personally use a managed Postgres database instead of running it on the Kubernetes cluster directly:
https://docs.digitalocean.com/products/databases/postgresql/
Hope that this helps!
Best,
Bobby