I'm playing around with kubernetes ConfigMaps. In the official documentation, I see "file-like keys" in the data
field:
apiVersion: v1
kind: ConfigMap
metadata:
name: game-demo
data:
# file-like keys
game.properties: |
enemy.types=aliens,monsters
player.maximum-lives=5
user-interface.properties: |
color.good=purple
color.bad=yellow
allow.textmode=true
Is it possible to break these "file-like keys" into different files and reference them in this ConfigMap resource?
I see several benefits of this approach:
- Proper syntax highlighting for the "file-like" configurations
- Can run auto formatters against the "file-like" configurations
Yes, it is easier to save the files as proper files on your machine and in Git.
I propose that you use the kustomize feature of kubectl and use configMapGenerator to generate the ConfigMap instead.
Example kustomization.yaml
(saved in the same directory as your files, e.g. in config/
)
configMapGenerator:
- name: game-demo
files:
- game.properties
- user-interface.properties
Then you can apply (and generate the configMap) with (if your config is in config/
):
kubectl -k config/
Or you can preview the "generated" configMap with:
kubectl kustomize config/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With