<p>I have a config map that looks like this:</p>
<pre><code>kubectl describe configmap example-config --namespace kube-system
Name:         example-config
Namespace:    kube-system
Labels:       &lt;none&gt;
Annotations:  &lt;none&gt;

Data
====
mapRoles:
----
- rolearn: arn:aws:iam::0123456789012:role/user-role-1
  username: system:node:{{EC2PrivateDNSName}}
  groups:
  - system:bootstrappers
  - system:nodes
- rolearn: arn:aws:iam::0123456789012:role/user-role-2
  username: system:node:{{EC2PrivateDNSName}}
  groups:
  - system:bootstrappers
  - system:nodes
</code></pre>
<p>I want to remove user-role-2 from the configmap. I think I need to use kubectl patch with a &quot;remove&quot; operation. What is the syntax to remove a section from a config map?</p>
<p>Here is an example command I can use to append to the config map:</p>
<pre><code>kubectl patch -n=kube-system cm/aws-auth --patch &quot;{\&quot;data\&quot;:{\&quot;mapRoles\&quot;: \&quot;- rolearn: &quot;arn:aws:iam::0123456789012:role/user-role-3&quot; \n  username: system:node:{{EC2PrivateDNSName}}\n  groups:\n  - system:bootstrappers\n  - system:nodes\n\&quot;}}&quot; 
</code></pre>

Dan
<p>According to kubernetes official docs:
<a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/</a></p>
<p>There is not such syntax in <code>kubectl patch</code> to remove a section from an api object like a config map.</p>
<blockquote>
<p>Here is an example command I can use to append to the config map:</p>
<p><code>kubectl patch -n=kube-system cm/aws-auth --patch &quot;{\&quot;data\&quot;:{\&quot;mapRoles\&quot;: \&quot;- rolearn: &quot;arn:aws:iam::0123456789012:role/user-role-3&quot; \n  username: system:node:{{EC2PrivateDNSName}}\n  groups:\n  - system:bootstrappers\n  - system:nodes\n\&quot;}}&quot;  </code></p>
</blockquote>
<p>The command above is used to replace the whole data field in configmap. So you can simply use it to patch update with the data you want:</p>
<pre><code>kubectl patch -n=kube-system cm/example-config --patch '{&quot;data&quot;:{&quot;mapRoles&quot;: &quot;- rolearn: arn:aws:iam::0123456789012:role/user-role-1\n  username: system:node:{{EC2PrivateDNSName}}\n  groups:\n  - system:bootstrappers\
n  - system:nodes&quot;}}'
</code></pre>
