<p>I have a config I need to apply from kubectl, but I don't quite understand what it is:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
data:
  localHosting.v1: |
    host: &quot;localhost:1234&quot;
    containerHost: &quot;container-name:5555&quot;
</code></pre>
<p>I can't figure out how to make this configmap using a <code>kubectl create configmap</code> invocation though. I thought that ConfigMaps were just key-value pairs, and the usage of the <code>--from-literal</code> flag seems to expect that, but this config seems to have an additional level of nesting.</p>
<p>I know you could typically create a YAML file or pipe in the whole YAML file using a heredoc, but that's not a very good solution in my situation. Is there a way to craft <code>kubectl create configmap</code> command to do this?</p>

Stabby
<blockquote>
<p>I thought that ConfigMaps were just key-value pairs...</p>
</blockquote>
<p>They <em>are</em> just key-value pairs. In your example, <code>localHosting.v1</code> is the key, and the string...</p>
<pre><code>host: &quot;localhost:1234&quot;
containerHost: &quot;container-name:5555&quot;
</code></pre>
<p>...is the value. You can create this from the command line by running something like:</p>
<pre><code>kubectl create cm myconfigmap '--from-literal=localHosting.v1=host: &quot;localhost:1234&quot;
containerHost: &quot;container-name:5555
'
</code></pre>
<p>Which results in:</p>
<pre><code>$ kubectl get cm myconfigmap -o yaml

apiVersion: v1
data:
  localHosting.v1: |
    host: &quot;localhost:1234&quot;
    containerHost: &quot;container-name:5555
kind: ConfigMap
metadata:
  creationTimestamp: &quot;2023-07-14T02:28:14Z&quot;
  name: myconfigmap
  namespace: sandbox
  resourceVersion: &quot;57813424&quot;
  uid: a126c38f-6836-4875-9a1b-7291910b7490
</code></pre>
<p>As with any other shell command, we use single quotes (<code>'</code>) to quote a multi-line string value.</p>
