Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubernetes configmap set from-file in yaml configuration

how can I describe this command in yaml format?

kubectl create configmap somename --from-file=./conf/nginx.conf 

I'd expect to do something like the following yaml, but it doesn't work

apiVersion: v1 kind: ConfigMap metadata:   name: somename   namespace: default fromfile: ./conf/nginx.conf 

any idea?

like image 446
Maoz Zadok Avatar asked Jul 10 '18 14:07

Maoz Zadok


People also ask

How do I create a ConfigMap from Yaml file in Kubernetes?

The simplest way to create a ConfigMap is to store a bunch of key-value strings in a ConfigMap YAML file and inject them as environment variables into your Pods. After that, you can reference the environment variables in your applications using whatever methods is necessary for your programming language.

How do I create a config map from a file?

You can use kubectl create configmap to create a ConfigMap from multiple files in the same directory. When you are creating a ConfigMap based on a directory, kubectl identifies files whose basename is a valid key in the directory and packages each of those files into the new ConfigMap.

Can you add a file to ConfigMap?

Create ConfigMapThe most common use case for --from-file is adding individual files, but it can also target directories as well. If the value of the --from-file flag is a directory, kubectl will scan the directory and add each file as a key-value pair in the ConfigMap.

How do I mount a file in ConfigMap?

Mount the configmap into the application container Create a container using the specified image from DockerHub; Make the configmap clusters-config-file available as a mountable volume called clusters-config-volume ; and. Mount that volume into the container at the path /clusters-config.


1 Answers

That won't work, because kubernetes isn't aware of the local file's path. You can simulate it by doing something like this:

kubectl create configmap --dry-run=client somename --from-file=./conf/nginx.conf --output yaml 

The --dry-run flag will simply show your changes on stdout, and not make the changes on the server. This will output a valid configmap, so if you pipe it to a file, you can use that:

kubectl create configmap --dry-run=client somename --from-file=./conf/nginx.conf --output yaml | tee somename.yaml 
like image 162
jaxxstorm Avatar answered Oct 01 '22 22:10

jaxxstorm