---
apiVersion: v1
kind: Pod
metadata:
  name: api-db
spec:
  containers:
    - name: api-database
      image: postgres:latest
      env:
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: api-secret
              key: POSTGRES_PASSWORD      
      volumeMounts:
      - mountPath: "/var/lib/postgresql"
        name: api-data
  initContainers:
  - name: pgsql-data-permission-fix
    image: busybox
    command: ["/bin/chmod","-R","777", "/data"]
    volumeMounts:
    - name: api-data
      mountPath: /data
  volumes:
    - name: api-data
      persistentVolumeClaim:
        claimName: api-pvc