I'm running into an issue in which my postgres deployment will not correctly create the database and I'm not sure why. The 2 sql files should help create the db with the right permissions and then stay in the persistent volume and persist between pod deployments until I clean it up.
At the moment, the deployment will deploy, restart the pod within 3-4 seconds and then skip any database initialization because it has already detected a database but not using my sql files. The deployment doesn't then work correctly.
Where is my "/mnt/data" folder from the PVC mounted?
How do I see the logs from the restarted container?
Am I doing something wrong in my yaml files? I have followed a guide but I always run into issues with storage and mounted volumes.
Docker version 20.10.8, build 3967b7d
Docker k8s - v1.21.5
Ubuntu 20.04
Windows 10 19043.1288
This is the persistent volume and persistent volume claim yaml file.
kind: PersistentVolume
apiVersion: v1
metadata:
name: postgres-pv-volume
labels:
type: local
app: postgres
spec:
storageClassName: manual
persistentVolumeReclaimPolicy: Retain
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pv-claim
labels:
app: postgres
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
This is part of the postgres deployment yaml file that specifies the storage
volumeMounts:
- mountPath: /docker-entrypoint-initdb.d/db1_srvc.sql
name: postgres1
- mountPath: /docker-entrypoint-initdb.d/db2_srvc.sql
name: postgres2
- mountPath: /var/lib/postgresql/data
name: pgdata
volumes:
- name: postgres1
hostPath:
path: /mnt/c/Data/init/db1_srvc.sql
- name: postgres2
hostPath:
path: /mnt/c/Data/init/db2_srvc.sql
- name: pgdata
persistentVolumeClaim:
claimName: postgres-pv-claim
SQL file contents
CREATE USER db1_srvc WITH PASSWORD 'db1_srvc';
CREATE DATABASE db1_srvc;
GRANT ALL PRIVILEGES ON DATABASE db1_srvc TO db1_srvc;