Repository: kubernetes
Issue: Anonymous volumes not counted against pod ephemeral-storage limits
Labels: kind/bug,needs-sig,needs-triage

### What happened?

Hi, not sure if this is the correct place to report, but we're seeing an issue between K8s and containerd with tracking disk usage against ephmeral-storage limits.

We have K8s (AWS EKS) v1.26.15 with containerd 1.7.22 running on Amazon Linux 2 with cgroups v1.  If you apply the below K8s manifest you should get a pod that uses around 1 GiB of disk in either an anonymous volume (coming from the VOLUME instruction in the Dockerfile that created the image), or by switching to alternate value of `DEST_DIR` the container root file system or a named volume.

For the container root filesystem, I see the usage briefly appear in `crictl stats` before the pod is evicted due to exceeding its `ephemeral-storage` limit.  For the named volume, `crictl stats` stays at zero but the pod is similarly killed.  However for the anonymous volume case `crictl stats` stays similarly on zero but the pod remains running, as presumably K8s is not counting the usage towards the total.

While I can see both volumes in `crictl inspect` under status/mounts I'm not sure if containerd/cri or the kubelet is meant to be reporting the disk usage of volumes.  `kubectl get --raw /api/v1/nodes/$MY_NODE/proxy/stats` only shows the named volume, not anonymous ones.

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: test-es-limit
  namespace: default
spec:
  nodeSelector:
    kubernetes.io/os: linux
    kubernetes.io/arch: amd64
  terminationGracePeriodSeconds: 1
  containers:
    - name: test
      image: postgres
      env:
        - name: DEST_DIR
          value: /var/lib/postgresql/data # Anon volume
          # value: /var/lib/misc # Container root fs
          # value: /data # Named volume
        - name: BIG_FILE
          value: /usr/lib/postgresql/17/bin/postgres # 9.6 MiB
      command:
        - bash
        - -c
        - "for RUN in {1..100}; do cp $BIG_FILE $DEST_DIR/dummy.$RUN ; done ; du -sh $DEST_DIR ; sleep 5000"
      resources:
        limits:
          cpu: 100m
          ephemeral-storage: 200Mi # Script uses almost 1 GiB
          memory: 128Mi
        requests:
          cpu: 100m
          ephemeral-storage: 200Mi
          memory: 128Mi
      volumeMounts:
        - name: named-storage
          mountPath: /data
  volumes:
    - name: named-storage
      emptyDir: {}
```

### What did you expect to happen?

For the pod described by the above YAML to get Evicted as using over storage limits

### How can we reproduce it (as minimally and precisely as possible)?

See included pod YAML

### Anything else we need to know?

_No response_

### Kubernetes version

<details>
v1.26.15
</details>


### Cloud provider

<details>
AWS - EKS v1.26
</details>


### OS version

<details>

```console
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
SUPPORT_END="2025-06-30"

Linux HOSTNAME 5.10.226-214.880.amzn2.x86_64 #1 SMP Tue Oct 8 16:18:15 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

</details>


### Install tools

_No response_

### Container runtime (CRI) and version (if applicable)

<details>
containerd 1.7.22
</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

_No response_