【发布时间】:2019-10-07 20:19:49
【问题描述】:
我的目标是在 minikube 上运行 postgres,/var/lib/postgresql/data 是从我的笔记本电脑安装的。
我关注了很多关于如何到达那里的帖子,但还没有成功,我得到的最接近的是这里:
首先,我将本地 /data/ 挂载到 minikube 并确认 - 据我了解,/data 具有 root 权限,因此我需要执行 sudo mkdir -p /data/postgres-pv 和 sudo cp -R <source_path>/data/* /data/postgres-pv 将数据复制到那里。
我的 PV 是:
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
为了调试,我能够运行一个busybox pod并确保我看到了正确的数据,我厌倦了在我的笔记本电脑上的/data/postgres-pv添加文件并立即使用以下命令在busybox安装路径中看到它们声明:
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
我用来调试的busybox:
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
当我尝试将相同的文件夹从本地笔记本电脑加载到运行 postgres 的 pod 中并覆盖 /var/lib/postgresql/data 时出现错误,我尝试了以下不同的变体,包括 subPath 和 PGDATA 变量,在许多情况下都可以看到帖子(例如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
我检查日志时得到的错误是:
+ 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
如果我修改部署以包含
- name: PGDATA
value: /var/lib/postgresql/data/pgdata/
然后错误变为:
+ 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
确实感觉我在所有不同的帖子之间兜圈子,而在这个过程中错过了一些基本的东西,非常感谢任何帮助或指向正确方向的点 - 感觉我需要在我的部署,它会工作!或更改我笔记本电脑上的权限。
【问题讨论】:
标签: postgresql minikube