What does key mean when creating a kubernetes configmap from a file

6/1/2019

I see here a syntax like this:

kubectl create cm configmap4 --from-file=special=config4.txt

I did not find a description of what repetition of = and the special means here. Kubernetes documentation here only denotes one time usage of \= after --from-file while creating configmaps in kubectl.

-- Farshid
kubectl
kubernetes

2 Answers

6/1/2019
kubectl create configmap my-config --from-file=path/to/bar

When creating a configmap based on a file, the key will default to the basename of the file, and the value will default to the file content. If the basename is an invalid key, you may specify an alternate key.


Create a new configmap named my-config with specified keys instead of file basenames on disk

kubectl create configmap my-config --from-file=key1=/path/to/bar/file1.txt --from-file=key2=/path/to/bar/file2.txt
-- Abu Hanifa
Source: StackOverflow

6/1/2019

It appears from generating the YAML that this middle key mean all the keys that are being loaded from the file to be nested inside the mentioned key (special keyword in the question example).

It appears like this:

apiVersion: v1
data:
  special: |
    var3=val3
    var4=val4
kind: ConfigMap
metadata:
  creationTimestamp: "2019-06-01T08:20:15Z"
  name: configmap4
  namespace: default
  resourceVersion: "123320"
  selfLink: /api/v1/namespaces/default/configmaps/configmap4
  uid: 1582b155-8446-11e9-87b7-0800277f619d
-- Farshid
Source: StackOverflow