我的目标是在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容器并确保查看正确的数据,我很累在/ 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
[我确实感觉到我在所有不同职位之间徘徊,而在此过程中缺少一些基本知识,因此非常感谢任何帮助或指向正确方向-感觉我需要在部署中更改一两行它会工作!或更改我的笔记本电脑上的权限。
将volumeMounts
更改为:
volumeMounts:
- mountPath: /var/lib/postgresql/something
name: postgres-pvc
您可以阅读PostgreSQL 9.6部分18.2. Creating a Database Cluster的文档:
18.2.1。使用辅助文件系统
许多安装在文件系统(卷)上而不是在计算机的“根”卷上创建数据库集群。如果选择执行此操作,建议不要尝试使用辅助卷的最顶层目录(装入点)作为数据目录。最佳实践是在PostgreSQL用户拥有的安装点目录中创建一个目录,然后在其中创建数据目录。这样可以避免权限问题,尤其是对于诸如pg_upgrade之类的操作而言,并且还可以确保在辅助卷脱机后清除失败。