<p>I have <code>sizeLimit</code> property under <code>emptyDir</code> set to 2Gi in my template base file. I want to remove the <code>sizelimit</code> and just have <code>emptyDir: {}</code>. I've been unable to achieve this using Kustomization overlays. I will detail my folder structure and kustomization yamls below.</p>
<p><strong>Folder Structure:</strong></p>
<pre><code>application
├── majorbase
│   ├── kustomization.yaml
│   └── resources
│       └── web-template.yaml
├── minorbase
│   ├── kustomization.yaml
│   └── resources
└── myoverlays
    ├── kustomization.yaml
    └── resources
        └── my-new-web.yaml
</code></pre>
<p>The folder <code>myoverlays</code> contains the following contents in it's kustomization.yaml file</p>
<pre><code>bases:
- ../minorbase
patchesStrategicMerge:
- resources/my-new-web.yaml
</code></pre>
<p>The folder <code>minorbase</code> contains the following contents in it's kustomization.yaml file</p>
<pre><code>bases:
- ../majorbase
</code></pre>
<p>The folder <code>majorbase</code> contains the following contents in it's kustomization.yaml file</p>
<pre><code>resources:
- resources/web-template.yaml
</code></pre>
<p>The section I want to edit looks like this in the majorbase/template.</p>
<pre><code>volumes:
      - name: test-vol
        emptyDir:
          sizeLimit: &quot;2Gi&quot;
</code></pre>
<p>The above configuration needs to be updated using overlays as below.</p>
<pre><code>volumes:
      - name: test-vol
        emptyDir: {}
</code></pre>
<p>This is where my problem lies. Kustomization just picks the 2Gi value mentioned in the base whenever I remove the <code>sizelimit</code> in my overlays. When I mention different value to <code>sizeLimit</code> such as &quot;1Gi&quot; in my overlays file, kustomization is picking up the change. What is the cause of this behaviour? Is it possible to achieve what I'm trying to do here?</p>

vishal
<p>NB: This answer assumes a recent version of Kustomize (I'm running 4.5.2 locally). Your examples are using deprecated syntax (the <code>bases</code> section was deprecated <a href="https://github.com/kubernetes-sigs/kustomize/blob/661743c7e5bd8c3d9d6866b6bc0a6f0e0b0512eb/site/content/en/blog/releases/v2.1.0.md#resources-expanded-bases-deprecated" rel="nofollow noreferrer">in version 2.1.0</a>, for example).</p>
<hr />
<p>Your problem is that you're using a <code>strategicMerge</code> patch, and you're merging and empty map (<code>{}</code>) with <code>{&quot;sizeLimit&quot;: &quot;26gi&quot;}</code>. If you merge an empty map with anything, it's a no-op: you end up with the &quot;anything&quot;.</p>
<p>To explicitly delete an element, you have a few choices.</p>
<p>You can use the <code>$patch: replace</code> directive (you can find an example of that <a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/inlinePatch.md" rel="nofollow noreferrer">here</a>) to have Kustomize <em>replace</em> the <code>emptyDir</code> element, rather than merging the contents. That would look like:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: example
spec:
  volumes:
    - name: test-vol
      emptyDir:
        $patch: replace
</code></pre>
<p>The corresponding <code>kustomization.yaml</code> might look something like:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../../base

patches:
  - path: resources/my-new-web.yaml
</code></pre>
<hr />
<p>Alternately, you can use a JSONPatch patch, which is good for explicitly deleting fields:</p>
<pre><code>- path: /spec/volumes/0/emptyDir/sizeLimit
  op: remove
</code></pre>
<p>Where <code>kustomization.yaml</code> would look like:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ....//base

patches:
  - target:
      kind: Pod
      name: example
    path: resources/my-new-web.yaml
</code></pre>
<hr />
<p>You can find a complete runnable demonstration of this <a href="https://github.com/larsks/so-example-72086055" rel="nofollow noreferrer">here</a>.</p>
