How to supply a value of a server in NFS mount in a k8 Deployment via a ConfigMap

8/7/2021

I'm writing a helm chart where I need to supply a nfs.server value for the volume mount from the ConfigMap (efs-url in the example below).

There are examples in the docs on how to pass the value from the ConfigMap to env variables or even mount ConfigMaps. I understand how I can pass this value from the values.yaml but I just can't find an example on how it can be done using a ConfigMap.

I have control over this ConfigMap so I can reformat it as needed.

  1. Am I missing something very obvious?
  2. Is it even possible to do?
  3. If not, what are the possible workarounds?
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: efs-url
data:
  url: yourEFSsystemID.efs.yourEFSregion.amazonaws.com

---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: efs-provisioner
spec:
  replicas: 1
  strategy:
    type: Recreate 
  template:
    metadata:
      labels:
        app: efs-provisioner
    spec:
      containers:
        - name: efs-provisioner
          image: quay.io/external_storage/efs-provisioner:latest
          env:
            - name: FILE_SYSTEM_ID
              valueFrom:
                configMapKeyRef:
                  name: efs-provisioner
                  key: file.system.id
            - name: AWS_REGION
              valueFrom:
                configMapKeyRef:
                  name: efs-provisioner
                  key: aws.region
            - name: PROVISIONER_NAME
              valueFrom:
                configMapKeyRef:
                  name: efs-provisioner
                  key: provisioner.name
          volumeMounts:
            - name: pv-volume
              mountPath: /persistentvolumes
      volumes:
        - name: pv-volume
          nfs:
            server:  <<< VALUE SHOULD COME FROM THE CONFIG MAP >>>
            path: /
-- Valera Maniuk
configmap
kubernetes
kubernetes-helm
mounted-volumes

1 Answer

8/20/2021

Having analysed the comments it looks like using ConfigMap approach is not suitable for this example as ConfigMap

is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume.

To read more about ConfigMaps and how they can be utilized one can visit the "ConfigMaps" section and the "Configure a Pod to Use a ConfigMap" section.

-- Jakub Siemaszko
Source: StackOverflow