kubectl create configmap - options to remove file names from output configmap when generateing using --file-name option

3/8/2021

I am using kubectl create configmap command as follows:

kubectl create configmap config-multi-yaml-files --from-file=templates/1template.yaml --from-file=apps/app1.yaml --from-file=app2/app2.yaml  --dry-run=true -o yaml > output.yaml

The resultant configmap do have file names (app1.yaml, app2.yaml) like this:

apiVersion: v1
data:
  app1.yaml: |-
  groups:
  - name: sample
    rules:
    - alert: alert

How can I use this command so that I do have a configmap from multiple yamls, but do not have the respective file names in the resultant configmap.

Any pointers are appreciated.

Thanks.

-- Himanshu Singh
amazon-eks
configmap
kubectl
kubernetes

1 Answer

3/23/2021

Unfortunately, you will have to use keys in order to make it work. But here is an example of what you could do:

kubectl create configmap config-multi-yaml-files --from-file <(cat templates/1template.yaml) --from-file <(cat apps/app1.yaml) --dry-run=client -o yaml

That way the keys would be numbers: 11, 12, 13...

So you will not have to use file names in your ConfigMap but keys will have to be used.

-- WytrzymaƂy Wiktor
Source: StackOverflow