Consuming ConfigMap Records Created from Property Files

A sample documentation ( http://kubernetes.io/docs/user-guide/configmap/ ) for consuming values ​​is based on ConfigMap, where each data item represents one pair / value, Example:

apiVersion: v1 kind: ConfigMap metadata: name: special-config namespace: default data: special.how: very special.type: charm 

However, when we create a ConfigMap from property files, each data entry value is a list of key / pair values. Example:

 $ kubectl get configmaps game-config -o yaml apiVersion: v1 kind: ConfigMap metadata: name: game-config [...] data: game.properties: |- enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 [...] 

In this case:

  • How do we use one record (for example: enemy.cheat) as an environment variable?
  • How do we use all records (for example: all game.properties records) as a set of environment variables, assuming we just use each key as the name of an environment variable?
+5
source share
1 answer

You cannot use one entry as it is just one big text. I have two options:

  • Do not create a configuration card from a file. Instead, manually create each entry in ConfigMap. You will have to consume each key separately, although at least until this problem is resolved.

  • Do not use ConfigMap as environment variables. Instead, set this key as the volume and ask the application to read the key / values.

It seems that the second option will work well for you. This will allow you to continue to generate ConfigMap from the file, and also allow you to use all declared keys / values ​​without constantly changing the manifestations of Kubernetes.

Another advantage of setting up your ConfigMap as a volume is that it allows you to perform in-place updates in your configurations (assuming your application supports this). If you set ConfigMap keys as environment variables, the only way to update them is to restart the application.

+4
source

Source: https://habr.com/ru/post/1260367/


All Articles