【问题标题】:chown: /var/lib/postgresql/data/postgresql.conf: Read-only file systemchown: /var/lib/postgresql/data/postgresql.conf: 只读文件系统
【发布时间】:2019-01-23 21:11:43
【问题描述】:

我解决了安装/var/lib/postgresql/data 时的权限问题,方法是关注this answerinitContainers

现在我正在尝试将 postgresql.conf 挂载为卷,并且遇到了类似的权限问题,引发了 chown: /var/lib/postgresql/data/postgresql.conf: Read-only file system

我会错过什么?我尝试了很多不同的变体,但运气不佳。

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  serviceName: postgres
  replicas: 1
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: postgres
    spec:
      terminationGracePeriodSeconds: 10
      initContainers:
      - name: chmod-er
        image: busybox:latest
        command:
        - /bin/chown
        - -R
        - '0'
        - /var/lib/postgresql/data
        volumeMounts:
        - name: postgredb
          mountPath: /var/lib/postgresql/data
        - name: pg-config
          mountPath: /var/lib/postgresql/data/postgresql.conf
          subPath: postgresql.conf
      containers:
        - name: postgres
          image: mdillon/postgis:10-alpine
          ports:
            - containerPort: 5432
          volumeMounts:
            - name: postgredb
              mountPath: /var/lib/postgresql/data
              subPath: data
            - name: pg-config
              mountPath: /var/lib/postgresql/data/postgresql.conf
              subPath: postgresql.conf
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: postgres-pvc
        - name: pg-config
          configMap:
            name: pg-config
            items:
              - key: postgresql.conf
                path: postgresql.conf

【问题讨论】:

    标签: postgresql kubernetes google-kubernetes-engine


    【解决方案1】:

    从 kubernetes 1.8 开始,configmap 以只读方式挂载,摘自 CHANGELOG-1.8.md:

    更改要挂载的 secret、configMap、downAPI 和预计卷 只读,而不是允许应用程序写入数据,然后 自动还原它。直到 1.11 版本,设置功能 gate ReadOnlyAPIDataVolumes=false 将保留旧行为。 (#58720,@joelsmith)

    如果要更改从 configmap 挂载的文件,可以将其复制到另一个目录,然后对其进行更新。

    【讨论】:

    • 谢谢坤!真希望我早点看到。你救了我好几个小时的痛苦。
    【解决方案2】:

    更新您的实体配置并将只读设置为false

    volumeMounts:
    - name: postgredb
      mountPath: /var/lib/postgresql/data
      readOnly: false
    - name: pg-config
      mountPath: /var/lib/postgresql/data/postgresql.conf
      subPath: postgresql.conf
      readOnly: false
    

    【讨论】:

      猜你喜欢
      • 2022-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-11
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      • 2018-04-10
      相关资源
      最近更新 更多