Skip to content

Postgres AKS persistent volume mapping problem #833

Closed
@n4ch04

Description

@n4ch04

Using postgres in a AKS (Azure k8s Service) it is not possible to map a folder of the pod to a persistent volume. The contents of the mapped folder does not appear in pv.
If you manually create a file via azure portal into the pv you can't see it on the pod files and vice versa.
To reproduce it at first instance in aks cluster below is my setup:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: database-volume
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: azurefile
  resources:
    requests:
      storage: 1Gi

apiVersion: apps/v1
kind: Deployment
metadata:
  name: database
spec:
  replicas: 1
  selector:
    matchLabels:
      app: database
  template:
    metadata:
      labels:
        app: database
    spec:
      containers:
      - name: database
        image: postgres:latest
        ports:
        - containerPort: 5432
        env:
            - name: POSTGRES_USER
              value: XXXXXXX
            - name: POSTGRES_PASSWORD
              value: XXXXXXX
            - name: POSTGRES_DB
              value: XXXXXX
            - name: PGDATA
              value: /var/lib/postgresql/data
 
        volumeMounts:
        - name: database
          mountPath: /var/lib/postgresql
          subPath: backup
      volumes:
      - name: database
        persistentVolumeClaim:
          claimName: database-volume

As you can see I create a PVC (using storageClass azurefile) used by a deployment to map a persistent volume to store the contents of the database (avoiding permissions problems setting subPath in the volumeMount).

I have tried to create the pv using manual config (not using pvc’s, creating the volume and accesing it with a secret into the deployment), using azureDisk instead of azureFile storage and the problem persists, the contents of the data folder are not mapped and if the pod dies, data dies with it.
I also tried to change default postgres data folder through PGDATA env variable, play with permissions (777) of data folder files, and issue is always there, looks like the volume is not correctly mapped.
Talk with azure support guys and they do not have registered this as azure storage issue, looks like only appears when using postgres image.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions