0

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;
  • its mounted where you specfiy it with mountPah. I am not sure but it could be a subPath issue. https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath. You could also but the sql file content in a configmap and mount this with subpath. – The Fool Nov 05 '21 at 15:08
  • @OKWeather111 Could you please add information about your Kubernetes cluster - how did you set it up? – Andrew Skorkin Nov 08 '21 at 16:32
  • @Andrew Skorkin The cluster is local to my PC and using Docker Kubernetes. Super simple and just 1 docker-node. – OKWeather111 Nov 10 '21 at 14:54
  • Sorry but I not found information about Docker Kubernetes. Maybe you mean Docker Desktop? – Andrew Skorkin Nov 16 '21 at 11:36
  • Hi Andrew, info is here - https://www.docker.com/products/kubernetes. It's definitely Docker Kubernetes but it runs within Docker Desktop application. – OKWeather111 Nov 17 '21 at 09:14
  • Sorry for delay. If you are still interested in solving your problem, you can try the solution from this [question about Mounting Windows local folder into pod](https://stackoverflow.com/questions/69764778/mounting-windows-local-folder-into-pod). – Andrew Skorkin Dec 26 '21 at 00:11

0 Answers0