is it possible to map multiple path with the same pvc in kubernetes

Viewed 41

I have deployment a postgresql stateful service in kubernetes, now mapped the /bitnami/postgresql to the NFS volumn like this way:

spec:
  volumes:
    - name: dshm
      emptyDir:
        medium: Memory
    - name: data-reddwarf-postgresql-postgresql-general
      persistentVolumeClaim:
        claimName: data-reddwarf-postgresql-postgresql-general
  containers:
    - name: reddwarf-postgresql
      image: docker.io/bitnami/postgresql:13.3.0-debian-10-r75
      ports:
        - name: tcp-postgresql
          containerPort: 5432
          protocol: TCP
      env:
        - name: BITNAMI_DEBUG
          value: 'false'
        - name: POSTGRESQL_PORT_NUMBER
          value: '5432'
        - name: POSTGRESQL_VOLUME_DIR
          value: /bitnami/postgresql
        - name: PGDATA
          value: /bitnami/postgresql/data
        - name: POSTGRES_USER
          value: postgres
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: reddwarf-postgresql
              key: postgresql-password
        - name: POSTGRESQL_ENABLE_LDAP
          value: 'no'
        - name: POSTGRESQL_ENABLE_TLS
          value: 'no'
        - name: POSTGRESQL_LOG_HOSTNAME
          value: 'false'
        - name: POSTGRESQL_LOG_CONNECTIONS
          value: 'false'
        - name: POSTGRESQL_LOG_DISCONNECTIONS
          value: 'false'
        - name: POSTGRESQL_PGAUDIT_LOG_CATALOG
          value: 'off'
        - name: POSTGRESQL_CLIENT_MIN_MESSAGES
          value: error
        - name: POSTGRESQL_SHARED_PRELOAD_LIBRARIES
          value: pgaudit
      resources:
        limits:
          cpu: 600m
          memory: 1Gi
        requests:
          cpu: 250m
          memory: 256Mi
      volumeMounts:
        - name: dshm
          mountPath: /dev/shm
        - name: data-reddwarf-postgresql-postgresql-general
          mountPath: /bitnami/postgresql

now I want to add another folder /docker-entrypoint-preinitdb.d mapping from deployment to the NFS PV. Am I need to add a new PVC&PV for mapping the new folder? what should I do to use the same PV&PVC with multiple folder so that I did not need to add extra NFS mapping? I have already tried the config like this:

volumeMounts:
            - name: dshm
              mountPath: /dev/shm
            - name: data-reddwarf-postgresql-postgresql-general
              mountPath: /bitnami/postgresql
            - name: data-reddwarf-postgresql-postgresql-general
              mountPath: /docker-entrypoint-preinitdb.d

but the NFS folder did not create the container folder docker-entrypoint-preinitdb.d. Seems the mapping did not success.

1 Answers

You should definitely go with a separate volume.

Even if you manage to mount multiple times the same PV in different locations, each mount would still expose all the files and directory in the PV. If /docker-entrypoint-preinitdb.d contains a bunch of scripts and no actual data, you could use a ConfigMap instead of creating a new NFS PVC.

Related