Minikube安装postgres数据文件夹

时间:2019-10-03 13:44:26

标签: postgresql minikube

我的目标是在minikube上运行postgres,其中/var/lib/postgresql/data是从笔记本电脑上安装的。 我关注了很多关于如何到达那里的文章,但至今仍未成功,我最接近的是这里:

首先,我将本地/data/挂载到minikube并确认-据我所知/data具有root权限,因此我需要执行sudo mkdir -p /data/postgres-pvsudo 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

可以肯定的是,我在所有不同职位之间徘徊,而在此过程中缺少一些基本知识,因此非常感谢任何帮助或指向正确方向的感觉-感觉我需要在自己的一行中更改一两行部署,它将起作用!或更改笔记本电脑上的权限。

1 个答案:

答案 0 :(得分:1)

将您的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之类的操作,还可以确保在将辅助卷脱机后清除失败。