Can we specify --from-file option when creating a configmap using yaml

12/4/2020

I am creating a config map as below

kubectl create configmap testconfigmap --from-file=testkey=testfile.txt

As I am using helm charts, I would like to create the config map using YAML file instead of running kubectl, so something like:

apiVersion: v1
kind: ConfigMap
metadata:
  name: testconfigmap
data:
fromfile: testkey=testfile.txt

The --from-file allows me to pass the key and the value I read from the testfile.txt. But the fromfile doesn't work if I create configMap as YAML file.

-- Sanjay
configmap
kubernetes
kubernetes-helm

1 Answer

12/4/2020

The following command will generate the Yaml file you need to apply

kubectl create configmap testconfigmap —from-file=testkey=test file.txt —dry-run=client -o yaml > myconfigmap.yaml

Then you can just do

kubectl apply -f myconfigmap.yaml
-- camba1
Source: StackOverflow