With this we can create a configmap linked to external file.
kubectl create configmap database-config --from-file=database.properties
But when we edit the yaml, it will show that complete content of file is dumped there.
Is there anyway to just point to a file in yaml also so that I will keep the properties file in the same folder as the configmap yaml and appy the folder all the yamls with:
kubectl apply -f target_folder\
Please suggest.
What
configmap
isIn other words when
configmap
is created from external file (like your case) or from other values, API server will validate if everything is correct and then will save it toetcd
. This also explains reasons why when youedit
yourconfigmap
you see its entire context. This happens becauseconfigmap
is read frometcd
, not any external sources.This is also one of the reasons why it's not recommended to store save big files as configmaps or secrets - it will affect kubernetes cluster performance as all cluster's objects are stored within
etcd
.Kustomize
This is one of the way to achieve your requirement to run one command on creating/configuring
configmap
based on the file in the same directory. It is a standalone tool to customize Kubernetes objects through a kustomization file.I created a short and simple example to show the idea:
Test this, this command will only render configmap, it won't create it yet:
Final step is to apply it:
Short explanation to command above:
Useful links: