ConfigMap data (yml format) - Kubernetes ConfigMap data (yml format) - Kubernetes kubernetes kubernetes

ConfigMap data (yml format) - Kubernetes


A ConfigMap is a dictionary of configuration settings. It consists of key-value pairs of strings. Kubernetes then adds those values to your containers.

In your case you have to make them flat, because Kubernetes will not understand them.

You can read in the documentation about Creating ConfigMap that:

kubectl create configmap <map-name> <data-source>

where is the name you want to assign to the ConfigMap and is the directory, file, or literal value to draw the data from.

The data source corresponds to a key-value pair in the ConfigMap, where

  • key = the file name or the key you provided on the command line, and
  • value = the file contents or the literal value you provided on the command line.

You can use kubectl describe or kubectl get to retrieve information about a ConfigMap.

EDIT

You could create a ConfigMap from a file with defined key.

Define the key to use when creating a ConfigMap from a file

Syntax might look like this:

kubectl create configmap my_configmap --from-file=<my-key-name>=<path-to-file>And the ConfigMap migh look like the following:

apiVersion: v1kind: ConfigMapmetadata:  creationTimestamp: 2019-07-03T18:54:22Z  name: my_configmap  namespace: default  resourceVersion: "530"  selfLink: /api/v1/namespaces/default/configmaps/my_configmap  uid: 05f8da22-d671-11e5-8cd0-68f728db1985data:  <my-key-name>: |    key=value    key=value    key=value    key=value

Also I was able to find Create Kubernetes ConfigMaps from configuration files.

Functionality

The projector can:

  • Take raw files and stuff them into a ConfigMap
  • Glob files in your config repo, and stuff ALL of them in your configmap
  • Extract fields from your structured data (yaml/json)
  • Create new structured outputs from a subset of a yaml/json source by pulling out some fields and dropping others
  • Translate back and forth between JSON and YAML (convert a YAML source to a JSON output, etc)
  • Support for extracting complex fields like objects+arrays from sources, and not just scalars!


You need to mount the ConfigMap as Volume. Otherwise the content would live in environment variables. The example i post here is from https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume

apiVersion: v1kind: Podmetadata:  name: dapi-test-podspec:  containers:    - name: test-container      image: k8s.gcr.io/busybox      command: [ "/bin/sh", "-c", "ls /etc/config/" ]      volumeMounts:      - name: config-volume        mountPath: /etc/config  volumes:    - name: config-volume      configMap:        # Provide the name of the ConfigMap containing the files you want        # to add to the container        name: special-config  restartPolicy: Never


You mentioned, you're using the application.yaml in context of a Spring project. So if you don't care whether you use .yaml or .property configuration-files, you can just use property-files because configMap generation supports them. It works with the --from-env-file flag:

kubectl create configmap configmapname --from-env-file application.properties

So in your deployment-file you can directly access the keys:

...env:  - KEYNAME    valueFrom:       configMapKeyRef:          name: configmapname          key: KeyInPropertiesFile