3

I'm using minikube to run kubernetes locally. My local k8s have two pods which one of them is PostgreSQL and another one is my own app. I've mounted a PersistentVolume and PersistentVolumeClaim in order to make a stateful pod for PostgreSQL:

kind: PersistentVolume
apiVersion: v1
metadata:
  name: postgres-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/psql"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

Here is PostgreSQL deployment yaml file:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: postgres
    spec:
      containers:
      - name: postgres
        imagePullPolicy: Never
        image: postgres:9.6
        ports:
        - name: postgres
          containerPort: 5432
        volumeMounts:
        - mountPath: /var/lib/postgresql
          name: postgres-persistent-storage
      volumes:
      - name: postgres-persistent-storage
        persistentVolumeClaim:
          claimName: postgres-pv-claim

The problem is that PostgreSQL service doesn't start and this error occurs when I run its pod:

Error: /var/lib/postgresql/9.6/main is not accessible; please fix the directory permissions (/var/lib/postgresql/9.6/ should be world readable)
No PostgreSQL clusters exist; see "man pg_createcluster" ... (warning).

I've checked inside of PostgreSQL pod and I found that /var/lib/postgresql is empty, just like /data/psql In minikube host. Can anyone help?

6
  • Have you tried shelling into the minikube Node and checking that the dir exists with the right permissions like in kubernetes.io/docs/tasks/configure-pod-container/… ? Commented Aug 25, 2018 at 10:49
  • Are you running minikube in virtualbox? Commented Aug 25, 2018 at 11:03
  • @NicolaBen Yes, I'm using VirtualBox driver. Commented Aug 25, 2018 at 11:05
  • @RyanDawson What do you mean by right permission? Commented Aug 25, 2018 at 11:07
  • I'd give it full read-write for all users - chmod 777 Commented Aug 25, 2018 at 11:18

1 Answer 1

6

Change:

volumeMounts:
  - mountPath: /var/lib/postgresql

to

volumeMounts:
  - mountPath: /var/lib/postgresql/data

With the wrong mountPoint postgres executables were overridden.

I attach an image with the data I see from inside the pod (on the left) and from inside minikube space (on the right, the little shell from virtualbox).

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply, the postgres is now working but there's nothing in /var/lib/postgresql/data.
I'm using my own PostgreSQL image, does it make problem?
I used your files with the only correction I wrote on mountpoint. It's working for me. Try with the postgres official image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.