kubernetes configmap set from-file in yaml configuration

7/10/2018

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?

-- Maoz Zadok
google-cloud-platform
google-kubernetes-engine
kubectl
kubernetes

1 Answer

7/10/2018

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 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 somename --from-file=./conf/nginx.conf --output yaml | tee somename.yaml
-- jaxxstorm
Source: StackOverflow