Minikube mount postgres папка с данными - PullRequest
0 голосов
/ 03 октября 2019

Моя цель - запустить postgres на миникубе, где /var/lib/postgresql/data смонтировано с моего ноутбука. Я следил за многими сообщениями о том, как туда добраться, но пока не получилось, самое близкое, что я получил, это здесь:

Сначала я подключаю свой локальный /data/ к мини-кубу и подтверждаю, что - в моем понимании /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 и переопределить /var/lib/postgresql/data Я получаю сообщение об ошибке, я пробовал различные варианты следующего, включая переменные subPath и PGDATA, как это снова видно во многих сообщениях (пример здесь )

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 Ответ

1 голос
/ 07 октября 2019

Измените volumeMounts на:

        volumeMounts:
          - mountPath: /var/lib/postgresql/something
            name: postgres-pvc

Вы можете прочитать документацию PostgreSQL 9.6 section 18.2. Создание кластера базы данных :

18.2.1. Использование вторичных файловых систем

Многие установки создают свои кластеры базы данных в файловых системах (томах), отличных от «корневого» тома компьютера. Если вы решите сделать это, не рекомендуется пытаться использовать самый верхний каталог вторичного тома (точку монтирования) в качестве каталога данных. Рекомендуется создать каталог в каталоге точек монтирования, который принадлежит пользователю PostgreSQL, а затем создать в нем каталог данных. Это позволяет избежать проблем с разрешениями, особенно для таких операций, как pg_upgrade, а также гарантирует чистые сбои, если вторичный том отключен.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...