Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgres container with persistent data in kubernetes #560

Closed
AlpNek opened this issue Mar 18, 2019 · 3 comments
Closed

postgres container with persistent data in kubernetes #560

AlpNek opened this issue Mar 18, 2019 · 3 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@AlpNek
Copy link

AlpNek commented Mar 18, 2019

Trying to setup a kubernetes cluster and have created a persistent volume thus:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: postgres-pv-volume
  labels:
    type: local
    app: postgres
spec:
  storageClassName: manual
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/data/postgres"

where,
/data is a mounted filesystem on minikube startup, say $HOME/data.

A claim binds to the above pv:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pv-claim
  labels:
    app: postgres
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 2Gi

The postgres pod is created as follows:

apiVersion: v1
kind: Pod
metadata:
  name: postgres
  labels:
    app: postgres
    tier: backend
spec:
  hostname: postgres 
  containers:
  - name: postgres
    image: postgres:9.5
    imagePullPolicy: "IfNotPresent"
    ports:
      - containerPort: 5432
    envFrom:
      - configMapRef:
          name: postgres-config
    volumeMounts:
      - mountPath: "/var/lib/postgresql/data"
        name: postgresdb
  volumes:
    - name: postgresdb
      persistentVolumeClaim:
        claimName: postgres-pv-claim

However, the pod/container is never created. It complains:

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

initdb: could not access directory "/var/lib/postgresql/data": Permission denied

I have tried setting the permissions of the mounted directory to be owned by postgres:postgres but still getting the same error.

Thanks!

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Mar 18, 2019
@wglambert
Copy link

Are you using NFS for your persistent volume, how are those permissions set?

@yosifkit
Copy link
Member

By using $HOME/data do you mean you are using the Mounted Host Folders of minikube. From past experience with boot2docker and "Docker for Mac", I would assume it is not possible to chown or chmod the shared folder (or sub folders) as the entrypoint script would try if started normally. You most likely just need to run the postgres container as a different user (ie --user 1000:50 on docker run). You'll need to substitute in the user and group id of the owner of the shared folder as seen from the minikube VM. See the Arbitrary --user notes on the docs on the Docker Hub.

Other notes: The shared folder may not even support what postgres needs to run (like fsync: docker/for-win#445). In this case move to a named volume or a folder on the VM that isn't shared to the host. If the shared folder is owned by root see (#558 (comment)).

@wglambert
Copy link

Closing since this is an issue with your environment, for further help you could try asking the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

3 participants