kubernetes: Ephemeral storage limits error ContainerStatusUnknown
What happened?
Pods are not being cleaned up once Ephemeral storage limits are hit
k describe pods -n ephemeral-metrics grow-test-7484cd87cb-wvpgt
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m52s default-scheduler Successfully assigned ephemeral-metrics/grow-test-7484cd87cb-q9ngs to ephemeral-metrics-cluster-worker
Normal Pulled 4m53s kubelet Container image "local.io/local/grow-test:latest" already present on machine
Normal Created 4m53s kubelet Created container grow-test
Normal Started 4m53s kubelet Started container grow-test
Warning Evicted 4m51s kubelet Pod ephemeral local storage usage exceeds the total limit of containers 5Ki.
Normal Killing 4m51s kubelet Stopping container grow-test
Warning ExceededGracePeriod 4m41s kubelet Container runtime did not kill the pod within specified grace period.
$ kubectl get pods
ephemeral-metrics grow-test-7484cd87cb-7lxp4 0/1 ContainerStatusUnknown 1 2m31s
ephemeral-metrics grow-test-7484cd87cb-clqxj 0/1 ContainerStatusUnknown 1 3m3s
ephemeral-metrics grow-test-7484cd87cb-gpxfk 0/1 ContainerStatusUnknown 1 119s
ephemeral-metrics grow-test-7484cd87cb-gxqqr 0/1 ContainerStatusUnknown 1 3m35s
ephemeral-metrics grow-test-7484cd87cb-j8fb7 1/1 Running 0 23s
ephemeral-metrics grow-test-7484cd87cb-psjpf 0/1 ContainerStatusUnknown 1 55s
ephemeral-metrics grow-test-7484cd87cb-wvpgt 0/1 Error 0 4m13s
ephemeral-metrics grow-test-7484cd87cb-xqnnx 0/1 ContainerStatusUnknown 1 87s
What did you expect to happen?
Pods to be cleaned up when an error occurs and a status that reflects the error better.
How can we reproduce it (as minimally and precisely as possible)?
Add this to a pod manifest.
resources:
requests:
ephemeral-storage: "1Ki"
limits:
ephemeral-storage: "5Ki"
I used this containerfile. I can publish if needed. https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics/blob/master/DockerfileTestGrow
Anything else we need to know?
No response
Kubernetes version
Kind Cluster
Client Version: v1.28.4
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.27.0
Cloud provider
OS version
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here
# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
Install tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, …) and versions (if applicable)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 7
- Comments: 50 (32 by maintainers)
Commits related to this issue
- Fix for #122160 — committed to AnishShah/kubernetes by AnishShah 3 years ago
Hello, I’ve replicated this scenario using limited ephemeral storage, resulting in ContainerStatusUnknown pod status.
Output:
Kubelet attempts to clean up this pod but can’t find the containers already forcefully terminated. This scenario involves pods stuck in the
ContainerStatusUnknownstate not being automatically removed by Kubernetes GC. This occurs because Kubernetes’ current garbage collection policies primarily target terminated pods (with a phase of Succeeded or Failed) rather than pods with ContainerStatusUnknown status. It’s important to note that the kubelet’s garbage collection process is limited to the containers it directly manages.I believe the GC should consider clean those containers also
ContainerStatusUnknownstate. This scenario is reproducible with limited ephemeral storage with two containers and can be considered for triage.Thanks @skizot722 and @max0ne for a repro script. I was able to repro the issue in my cluster. I found out the root cause. I’m not familiar with the codebase, but I have a potential fix in https://github.com/AnishShah/kubernetes/commit/0663ab8f0a430312834ea3c16952d8b50a419cd6.
Root cause:
This is the code where we kill pods after eviction. Here, the container runtime only stops the container (but does not remove it) - https://github.com/kubernetes/kubernetes/blob/3df07e446b8c0befab3551c3001c71340710751c/pkg/kubelet/kubelet.go#L2025
After the pod is killed, we update the pod status here by fetching status from container runtime - https://github.com/kubernetes/kubernetes/blob/3df07e446b8c0befab3551c3001c71340710751c/pkg/kubelet/kubelet.go#L2043-L2088
Between step 1 and 2, there’s some race condition that is removing the container completely. So at step 2, it is unable to find any
ContainerStatusand hence, it setsContainerStatusUnknown. You can see from the logs here -Fix: I tried to find places in kubelet codebase where we are deleting the container and added a check to ensure that the pod is finished before deleting - https://github.com/AnishShah/kubernetes/commit/0663ab8f0a430312834ea3c16952d8b50a419cd6.
Behavior after the fix: I still saw one
ContainerStatusUnknownbut this is much less than the situation before the fix. But that makes me believe that this is not the correct fix.@skizot722 thanks for the quick reply. The “status” reported in
kubectl get podscan be misleading since it fuses a few fields together for better user experience. The controllers typically will decide their action based on the raw pod status from the API. That’s why I wanted to learn the actual status of the pod to help assess the impact.@AnishShah since you’ve reproduced this successfully in GKE, could you help get the pod status?
Experiencing the same issue on
v1.29.11-eks-56e63d8status
Thanks @AnishShah! In your example the pod has already failed (`phase: Failed), and it’s safe to reuse the IPs, etc.
We should still fix the confusing behavior, but the impact assessment will help us determine the urgency 😃
@skizot722 So I thought it was sad emoji, but it looks like I need to read before I click nextime lol.
Nothing to add on my end, this issue is out my wheel house but still curious!
@skizot722 I will bring this up in the next sig-node meeting.
@jmcgrath207 / @AnishShah thank you for the replies. This problem does not have to do with the underlying node being under disk pressure, from what we can tell. We have seen that in the past, and the pods are evicted w/o issue and the status message indicates that the eviction took place due to node disk pressure. In this case, the pod is evicted, every time. But the resulting pod status becomes
ContainerStatusUnknownwhen that happens, instead of the expected status ofError.My colleague was actually able to create a reproduction script and image. Hopefully you guys can give it a try and see the issue. His script does not produce the problem every single time, but it is able to trigger the issue. The repo for it is located here.
So if you are asking why these pods are still staying around after they are evicted, that is working as intended.
Pods are only GC if they reach the maximum limit set by the cluster (
--terminated-pod-gc-threshold). So I think this is actually intended.If the number of pods reaches that limit, then they will be dropped from the apiserver (etcd really).