<p>I'm trying to deploy postgres/postgis on GKE, but I continue to get the permission error: <code>initdb: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted</code>. I've tried various fixes that I've researched but I've yet to get passed this error. Below is my deployment yaml.</p>

<p>What am I missing?</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
    spec:
      terminationGracePeriodSeconds: 10
      securityContext:
        runAsUser: 1000
        fsGroup: 1000
      containers:
        - name: postgres
          image: mdillon/postgis:10
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_DB
              value: "database"
            - name: POSTGRES_USER
              value: "postgres"
            - name: POSTGRES_PASSWORD
              value: "postgres"
          volumeMounts:
            - name: postgredb
              mountPath: /var/lib/postgresql/data
              subPath: data
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: postgres-pvc
</code></pre>

Mike
<p>While it is not exactly the same question, this "use an <code>initContainer:</code> to <code>chmod</code>" answer will interest you: <a href="https://stackoverflow.com/questions/51200115/chown-changing-ownership-of-data-db-operation-not-permitted/51203031#51203031">chown: changing ownership of &#39;/data/db&#39;: Operation not permitted</a></p>
