1

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.

Andrzej Sydor
  • 1,373
  • 4
  • 13
  • 28
Sanjay
  • 61
  • 1
  • 2
  • Welcome to stackoverflow @Sanjay!!! To make it easier for others to help you consider providing a practical example of what you have tried, the output and short explanation of what you are trying to achieve. Also formatting your post makes is much easier for the people reading it, consider adding code blocks. – Filip Nikolov Dec 04 '20 at 08:36

1 Answers1

-2

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
  • 1,795
  • 2
  • 12
  • 18
  • This pair of commands can't be run in Helm. If you have a Helm chart typically it will be self-contained and checked into source control, and you wouldn't use imperative `kubectl create` commands. – David Maze Dec 04 '20 at 11:02