local-path-provisioner icon indicating copy to clipboard operation
local-path-provisioner copied to clipboard

Database file not found when using Postgres

Open huija opened this issue 3 years ago • 4 comments

  1. deploy Postgres on k3s
  2. cd local path, cd data and would see nothing image
  3. cd pod's mount path, cd data and would see files expected. image
  4. touch some file in local path or pod's mount path(except data/), it's ok to see them on both sides

huija avatar Jul 01 '22 08:07 huija

$ cat postgres-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-5432-pvc
  namespace: middlewares
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 512Mi
  storageClassName: "local-path"

huija avatar Jul 01 '22 08:07 huija

$ cat postgres-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
  namespace: middlewares
spec:
  serviceName: postgres-headless-svc
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:14
        ports:
        - containerPort: 5432
          protocol: TCP
        volumeMounts:
        - name: time-zone
          mountPath: /etc/localtime
        - name: postgres-data
          mountPath: /var/lib/postgresql
        env:
        - name: POSTGRES_PASSWORD
          value: yourpassword
      volumes:
      - name: postgres-data
        persistentVolumeClaim:
          claimName: postgres-5432-pvc
      - name: time-zone
        hostPath:
          path: /etc/localtime
---
apiVersion: v1
kind: Service
metadata:
  name: postgres-headless-svc
  namespace: middlewares
spec:
  ports:
  - port: 5432
    targetPort: 5432
  clusterIP: None
  selector:
    app: postgres

huija avatar Jul 01 '22 08:07 huija

        - name: postgres-data
          mountPath: /var/lib/postgresql/data

if I mount the local path to pg's data folder, I can see the files. image

huija avatar Jul 01 '22 08:07 huija

Events seem no problem. image

huija avatar Jul 01 '22 09:07 huija