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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With