3

I have a tool working on K8s that uses four configuration files:

falco-config/falco.yaml             
falco-config/falco_rules.local.yaml 
falco-config/falco_rules.yaml       
falco-config/k8s_audit_rules.yaml

At deployment time I create the config map for this tool using the command:

kubectl create configmap falco-config --from-file=..../falco-config/

It creates a ConfigMap with these four files. Now suppose I only want to update the falco_rules.yaml but I don't have (for different reasons) the other files. Which kubectl command can help me to do that? I searched for a solution on K8s doc and Stackoverflow with no luck.

Another question is, is there an example out there to do the same via K8s API in Javascript?

NOTE: I have read this question: Kubectl update configMap but it doesn't address the modify via API and the fact that I need to only update one file while the whole configuration is composed by 4 files.

Salvatore D'angelo
  • 1,019
  • 3
  • 14
  • 39
  • 1
    Does this answer your question? [Kubectl update configMap](https://stackoverflow.com/questions/49989943/kubectl-update-configmap) – Grigoriy Mikhalkin Apr 03 '20 at 11:08
  • No. See my note above. – Salvatore D'angelo Apr 03 '20 at 12:56
  • 1
    Hi again, reading better the question they are very similar. The question talks about a ConfigMap having only one configuration file where it is needed to change only one parameter. In my case, my ConfigMap is composed of 4 files and I need to update only one. Looking at the answer it seems that there is no solution for both unless you don't manipulate the ConfigMap programmatically. If you think this question is duplicated I have no objection and I am sorry for this. I did a search before submit it and I thought my question was different because I though a single file was changeble. – Salvatore D'angelo Apr 03 '20 at 13:03

1 Answers1

3

Unfortunately there is no way to update specific fields of the ConfigMap in one go. Assuming that the ConfigMap resource has been already created, you could work around this as follows:

  1. Fetch the ConfigMap resource: kubectl get configmap <name> --export -o yaml > config.yaml to fetch the ConfigMap resource locally
  2. Update the fields in config.yaml so that the values of falco_rules.yaml are properly injected. This can be done programmatically.
  3. kubectl apply -f config.yaml to reconfigure the existing ConfigMap resource
George Tseres
  • 498
  • 6
  • 19
  • 1
    Yes, I imagined a solution like this. But you got my problem. I wanted to avoid to manipulate a file programmatically and have a more elegant solution. – Salvatore D'angelo Apr 03 '20 at 12:47
  • Hello, I think the statement *there is no way to update specific fields* might be misleading in context of the below answer, where there's a proposal of doing so: https://stackoverflow.com/a/38216458/1815881 – Athlan Jul 27 '23 at 06:51