<p>I am familiar with Kubernetes <a href="https://kubernetes.io/docs/tasks/administer-cluster/limit-storage-consumption/" rel="nofollow noreferrer">documentation</a> that describes how to setup limits for PVC. However, what if the container is not assigned PVC?</p>
<p>Suppose a Kubernetes container that simply defines:</p>
<pre><code>- image: 'redis:7'
  name: redis
</code></pre>
<p>... I keep writing data to this Redis instance.</p>
<ul>
<li>How do I set a quota to ensure that the container does not use more than allocated storage?</li>
<li>How to inspect how much storage is already used?</li>
</ul>
<p>I have tried setting <code>ResourceQuota</code> for ephemeral resources such as:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ResourceQuota
metadata:
  labels:
  # {{ include &quot;app.resource_labels&quot; . | indent 4 }}
  name: '{{ .Release.Name }}'
spec:
  hard:
    configmaps: 10
    limits.cpu: 4
    limits.ephemeral-storage: 1Gi
    limits.memory: 10Gi
    pods: 30
    secrets: 5
    services: 20
</code></pre>
<p>However, when inspecting quota, it always says 0 for <code>ephemeral-storage</code>.</p>
<pre><code>kubectl describe quota
Name:                     gaia-review-contra-resource-quota-c79e5b3c
Namespace:                gaia-review-c79e5b3c
Resource                  Used     Hard
--------                  ----     ----
configmaps                2        10
limits.cpu                21       4
limits.ephemeral-storage  0        1Gi
limits.memory             25576Mi  10Gi
pods                      16       30
secrets                   4        5
services                  8        20
</code></pre>
<p>Therefore, I suspect that something else is not working as it should or I am looking at the wrong place.</p>
<p>Meanwhile, the VMs that are running these pods is experiencing disk pressure.</p>
<p><a href="https://i.stack.imgur.com/CUQ8B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CUQ8B.png" alt="VMs" /></a></p>
<p><a href="https://i.stack.imgur.com/114dZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/114dZ.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/5L8AJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5L8AJ.png" alt="enter image description here" /></a></p>
<p>My next best theory is that it is actually the Docker image layers that are filling the disk space, but I am unsure how to confirm that or why resources are not being freed.</p>

Gajus
<p>If the container is not assigned to PVC then assuming ephemeral storage is assigned will be used by default.</p>
<p>To ensure that the container does not use more than allocated storage set the <strong><code>memory limits field spec.containers[].resources.limits.memory</code></strong>.</p>
<p>Below example is taken from this <a href="https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#local-ephemeral-storage" rel="nofollow noreferrer">official kubernetes</a> doc, similarly you can also set limits to your containers.</p>
<pre><code>containers:

 - name: log-aggregator

   image: images.my-company.example/log-aggregator:v6

   resources:

     requests:

       ephemeral-storage: &quot;2Gi&quot;

     limits:

       ephemeral-storage: &quot;4Gi&quot;
</code></pre>
<p>As @larks suggested, this document contains a detailed explanation and more methods which will help you and you can also use <a href="https://kubernetes.io/docs/concepts/policy/resource-quotas/#resource-quota-per-priorityclass" rel="nofollow noreferrer">resource quotas</a> for storage to set limits.</p>
<p>For more information  you can also refer to the <a href="https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#example-1" rel="nofollow noreferrer">Resource Management for Pods and Containers</a> doc.</p>
