kubernetes: How to create and use configmap from multiple files kubernetes: How to create and use configmap from multiple files kubernetes kubernetes

kubernetes: How to create and use configmap from multiple files


One solution to this problem is to create a ConfigMap with a multiple data key/values:

apiVersion: v1kind: ConfigMapmetadata:  name: confdata:  game.properties: |    <paste file content here>  ui.properties: |    <paste file content here>

Just don't forget | symbol before pasting content of files.


Yes, a pod or deployment can get env From a bunch of configMapRef entries:

    spec:      containers:      - name: encouragement-api        image: registry-......../....../encouragement.api        ports:        - containerPort: 80        envFrom:          - configMapRef:              name: general-config          - configMapRef:              name: private-config

Best to create them from yaml files for k8s law and order:

config_general.yaml

apiVersion: v1kind: ConfigMapmetadata:  name: general-configdata:  HOSTNAME: Develop_hostname  COMPUTERNAME: Develop_compname  ASPNETCORE_ENVIRONMENT: Development

encouragement-api/config_private.yaml:

apiVersion: v1kind: ConfigMapmetadata:  name: private-configdata:  PRIVATE_STUFF: real_private

apply the two configmaps:

kubectl apply -f config_general.yamlkubectl apply -f encouragement-api/config_private.yaml

Run and exec into the pod and run env |grep PRIVATE && env |grep HOSTNAME

I have config_general.yaml laying around in the same repo as the developers' code, they can change it however they like. Passwords and sensitive values are kept in the config_private.yaml file which is sitting elsewhere (a S3 encrypted bucket) and the values there are base64 encoded for an extra bit of security.


am not sure if you can load all key:value pairs from a specific file in a configmap as environemnt variables in a pod. you can load all key:value pairs from a specific configmap as environemnt variables in a pod. see below

apiVersion: v1kind: ConfigMapmetadata:  name: special-config  namespace: defaultdata:  SPECIAL_LEVEL: very  SPECIAL_TYPE: charm
apiVersion: v1kind: Podmetadata:  name: dapi-test-podspec:  containers:    - name: test-container      image: gcr.io/google_containers/busybox      command: [ "/bin/sh", "-c", "env" ]      envFrom:      - configMapRef:          name: special-config  restartPolicy: Never

Verify that pod shows below env variables

SPECIAL_LEVEL=verySPECIAL_TYPE=charm