My goal is to run postgres on minikube, where /var/lib/postgresql/data
is mounted from my laptop.
I followed many posts on how to get there but unsuccesfull just yet, the closest I've gotten is here:
First I mount my local /data/
to minikube and confirm that - to my understanding the /data
has root permissions, so I needed to do sudo mkdir -p /data/postgres-pv
and sudo cp -R <source_path>/data/* /data/postgres-pv
to copy data over there.
My PV is:
kind: PersistentVolume
apiVersion: v1
metadata:
name: postgres-pv
namespace: demo
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /data/postgres-pv
For debug, I was able to run a busybox pod and make sure I'm seeing the right data, I tired adding files on my laptop at /data/postgres-pv and instantly seeing them in busybox mounted path using the following claim:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pvc
namespace: demo
labels:
type: local
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
volumeName: postgres-pv
The busybox I used for debug:
kind: Pod
apiVersion: v1
metadata:
name: busybox
namespace: demo
spec:
containers:
- name: busybox
image: busybox
command:
- sleep
- "3600"
volumeMounts:
- mountPath: "/data"
name: postgres-pvc
volumes:
- name: postgres-pvc
persistentVolumeClaim:
claimName: postgres-pvc
When I try to load the same exact folder from my local laptop into a pod running postgres and override /var/lib/postgresql/data
I get an error, I tried different variations of the following, including subPath and PGDATA variable as again, seen in many posts (example here)
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: admindb
namespace: demo # should be replaced
spec:
template:
metadata:
labels:
app: admindb
spec:
containers:
- name: postgres
image: postgres:9.6.5
ports:
- containerPort: 5432
env:
# - name: POSTGRES_DB
# valueFrom:
# secretKeyRef:
# name: admindb-secret-config
# key: dbname
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-credentials
key: user
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: password
# - name: PGDATA # overriding the default mount so we can load our own data from PVC
# value: /var/lib/postgresql/data/pgdata/
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgres-pvc
# subPath: pgdata
volumes:
- name: postgres-pvc
persistentVolumeClaim:
claimName: postgres-pvc
The error I get when I check the log is:
+ kubectl logs -n demo admindb-546d55d9b5-ddr4f
chown: cannot read directory ‘/var/lib/postgresql/data/pg_multixact’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/pgdata/pgdata’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/pgdata’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_wal’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_snapshots’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_commit_ts’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_stat’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/PG_VERSION’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_stat_tmp’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/pg_hba.conf’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/postmaster.pid’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_logical’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_notify’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_subtrans’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_serial’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_replslot’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/postgresql.conf’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/postgres/pgdata’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/postgres’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_tblspc’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/postgresql.auto.conf’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_twophase’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_xact’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/pg_dynshmem’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/postmaster.opts’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/pg_ident.conf’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/global’: Input/output error
chown: cannot read directory ‘/var/lib/postgresql/data/base’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data’: Input/output error
if I modify the deployment to include
- name: PGDATA
value: /var/lib/postgresql/data/pgdata/
The error then becomes:
+ kubectl logs -n demo admindb-6dc94659dd-4kc9t
chown: changing ownership of ‘/var/lib/postgresql/data/pgdata/pgdata’: Input/output error
chown: changing ownership of ‘/var/lib/postgresql/data/pgdata/’: Input/output error
It sure feels that I'm going in circles between all the different posts while missing something fundamental in the process, any help or point in the right direction is greatly appreciated - feel like I need to change a line or two in my deployment and it will work! or change a permission on my laptop.