EKS 1.18 Troubleshooting: 'Failed to Garbage Collect Required Images' Error - Fix Overlays Filesystem Full & Evicted Pods

Amazon Elastic Kubernetes Service (EKS) has become a cornerstone for running containerized applications at scale. However, like any distributed system, EKS clusters can encounter operational hurdles. One common issue in EKS 1.18 (and earlier versions) is the "Failed to Garbage Collect Required Images" error, often accompanied by Overlay filesystem (OverlayFS) exhaustion and pod evictions due to DiskPressure.

This error disrupts cluster stability: nodes run out of disk space, kubelet (the node-level Kubernetes agent) fails to clean up unused container images, and pods get evicted, leading to service downtime. In this blog, we’ll demystify this error, walk through root causes, provide step-by-step troubleshooting, and share fixes to restore your cluster—plus strategies to prevent recurrence.

Table of Contents#

  1. Understanding the "Failed to Garbage Collect Required Images" Error
  2. Root Causes: Why OverlayFS Fills Up & Pods Get Evicted
  3. Troubleshooting Steps
  4. Fixing the Issue
  5. Prevention Strategies
  6. Conclusion
  7. References

1. Understanding the "Failed to Garbage Collect Required Images" Error#

The error "Failed to Garbage Collect Required Images" originates from the kubelet, Kubernetes’ node agent responsible for managing pods and container lifecycle. It appears in kubelet logs when the agent attempts to free disk space by deleting unused container images but cannot do so because:

  • Required images (critical for cluster operation) are占用 significant disk space and cannot be deleted.
  • The Overlay filesystem (OverlayFS)—used by container runtimes (e.g., containerd) to store container images and layers—is full, leaving no room for garbage collection (GC).

What Triggers This?#

Kubelet runs ImageGC periodically to delete unused images, using thresholds (--image-gc-high-threshold and --image-gc-low-threshold) to determine when to trigger GC. If the disk usage exceeds the high threshold, kubelet deletes images until usage drops to the low threshold. However, if "required images" (e.g., pause containers, CNI plugins, or control plane images) occupy most of the disk space, kubelet cannot delete them, leaving no space to free. This causes OverlayFS to fill up, leading to DiskPressure on the node, which in turn triggers pod evictions.

2. Root Causes: Why OverlayFS Fills Up & Pods Get Evicted#

A. OverlayFS Exhaustion#

OverlayFS is the default storage driver for container runtimes like containerd (used in EKS 1.18+) and Docker. It stores container images as layered snapshots in /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/ (containerd) or /var/lib/docker/overlay2/ (Docker). OverlayFS fills up due to:

  • Too many images: Unused or stale container images accumulate over time.
  • Large images: Applications with bloated images (e.g., unoptimized base images) consume excessive space.
  • Insufficient disk allocation: EKS nodes with undersized EBS volumes (e.g., 20GB root volumes) lack space for image storage.

B. "Required Images" Blocking GC#

Kubelet marks certain images as "required" to ensure cluster stability. These include:

  • pause container (e.g., 602401143452.dkr.ecr.us-west-2.amazonaws.com/eks/pause:3.5 in EKS).
  • CNI plugins (e.g., amazon-k8s-cni).
  • Control plane images (e.g., CoreDNS, kube-proxy).

Kubelet cannot delete these images, even if they占用 disk space. If required images grow large (e.g., due to version bloat) or multiple versions are retained, they block ImageGC, exacerbating OverlayFS exhaustion.

C. Evicted Pods Worsening the Cycle#

When OverlayFS fills up, nodes hit the DiskPressure condition. Kubernetes then evicts pods to free space, but evicted pods often leave behind:

  • Uncleaned container logs.
  • Stale volumes (e.g., emptyDir volumes).
  • Orphaned snapshots in OverlayFS.

This residual data further reduces available disk space, creating a恶性循环 of evictions and OverlayFS bloat.

3. Troubleshooting Steps#

Let’s diagnose the issue with actionable commands and log analysis.

Step 1: Check Node Health & DiskPressure#

First, identify nodes experiencing DiskPressure:

kubectl get nodes -o wide  

Look for nodes with Ready,SchedulingDisabled or NotReady status. For a specific node, check conditions with:

kubectl describe node <node-name>  

In the Conditions section, look for:

Type                 Status  Reason               Message  
----                 ------  ------               -------  
DiskPressure         True    KubeletHasDiskPressure  kubelet has disk pressure  

This confirms the node is low on disk space.

Step 2: Inspect OverlayFS Usage#

OverlayFS is mounted at the container runtime’s data directory. For containerd (EKS 1.18+ default), this is typically /var/lib/containerd/.

Check Disk Usage#

SSH into the affected node (via AWS Systems Manager Session Manager or SSH key) and run:

df -h /var/lib/containerd  # Check overall usage  

If usage is >85% (default image-gc-high-threshold), ImageGC is likely failing.

Locate OverlayFS Mounts#

Use findmnt to confirm the OverlayFS mount point:

findmnt -t overlay  # For containerd, output may look like:  
# /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots  

Identify Large Directories#

Use du to find which subdirectories are consuming space. For containerd’s OverlayFS snapshots:

sudo du -sh /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/* | sort -rh | head -10  

This lists the 10 largest snapshot directories (each representing an image layer).

Step 3: Verify Image Garbage Collection (ImageGC) Configuration#

Check if kubelet’s ImageGC thresholds are misconfigured or if GC is failing.

Check Kubelet Config#

EKS nodes store kubelet config in /var/lib/kubelet/config.yaml. Inspect ImageGC settings:

grep -i imagegc /var/lib/kubelet/config.yaml  

Default values (EKS 1.18):

imageGCHighThresholdPercent: 85  
imageGCLowThresholdPercent: 80  

If imageGCHighThresholdPercent is set too high (e.g., 95%), ImageGC triggers too late.

Check Kubelet Logs#

Search kubelet logs for ImageGC failures:

journalctl -u kubelet | grep -i "garbage collect"  

Look for errors like:

E0101 12:34:56.789123 12345 kubelet.go:1345] Failed to garbage collect required images: failed to find space to garbage collect images: wanted to free 1073741824 bytes, but could only free 0 bytes  

This confirms kubelet cannot free space because required images block GC.

Step 4: Analyze Evicted Pods#

Evicted pods leave traces in Failed phase. List them across all namespaces:

kubectl get pods --all-namespaces --field-selector=status.phase=Failed  

Describe an evicted pod to confirm DiskPressure as the cause:

kubectl describe pod <pod-name> -n <namespace>  

Look for:

Status:  Failed  
Reason:  Evicted  
Message: The node was low on resource: ephemeral-storage. Container <container> was using 10Gi, which exceeds its request of 0.  

4. Fixing the Issue#

Fix 1: Manually Clean Up OverlayFS#

Free space by deleting unused images (excluding "required images"). Use crictl (container runtime CLI) to manage images in containerd.

List All Images#

crictl images  # Lists all images with IDs and sizes  

Identify Unused Images#

Filter images not used by running pods. First, get running pod image IDs:

RUNNING_IMAGES=$(crictl pods --quiet | xargs -I {} crictl inspect {} | jq -r '.status.image.id' | sort -u)  

Then list unused images:

crictl images --quiet | grep -vFf <(echo "$RUNNING_IMAGES")  

Delete Unused Images#

Delete unused images (carefully! Avoid deleting required images like pause or CNI plugins):

crictl images --quiet | grep -vFf <(echo "$RUNNING_IMAGES") | xargs -I {} crictl rmi {}  

Clean Up Stale Snapshots#

Containerd may leave orphaned snapshots. Use ctr (containerd’s admin CLI) to prune them:

sudo ctr -n k8s.io snapshots prune  

Fix 2: Reconfigure Kubelet ImageGC Thresholds#

Lower the ImageGC high threshold to trigger GC earlier. For EKS nodes, update the kubelet config via the EKS node bootstrap script or AWS Launch Template.

Update Kubelet Config#

Edit /var/lib/kubelet/config.yaml (temporarily; for permanence, use Launch Templates):

imageGCHighThresholdPercent: 80  # Lower from 85%  
imageGCLowThresholdPercent: 75   # Lower from 80%  

Restart kubelet to apply changes:

sudo systemctl restart kubelet  

Verify GC Runs#

Check logs to confirm ImageGC now works:

journalctl -u kubelet | grep -i "successfully garbage collected"  

Fix 3: Resolve Evicted Pods & Break the Cycle#

Evicted pods must be deleted to clear residual data. Use --force to bypass graceful termination:

kubectl delete pod <pod-name> -n <namespace> --grace-period=0 --force  

For bulk deletion (use cautiously!):

kubectl get pods --all-namespaces --field-selector=status.phase=Failed -o jsonpath='{.items[*].metadata.name}' | xargs -I {} kubectl delete pod {} --grace-period=0 --force  

After freeing space, pods managed by Deployments/StatefulSets will restart automatically.

5. Prevention Strategies#

A. Allocate Sufficient Disk Space#

Use EKS node groups with minimum 50GB EBS volumes (recommend 100GB+ for production). Resize existing volumes via AWS EC2:

aws ec2 modify-volume --volume-id <vol-id> --size 100  
# Then extend the filesystem on the node: sudo resize2fs /dev/xvda1  

B. Automate Image Cleanup#

Schedule regular image pruning with crictl:

# Add to crontab (run daily at 2 AM)  
echo "0 2 * * * root crictl rmi \$(crictl images --quiet | grep -vFf <(crictl pods --quiet | xargs -I {} crictl inspect {} | jq -r '.status.image.id' | sort -u))" | sudo tee -a /etc/crontab  

C. Monitor OverlayFS & DiskPressure#

Use Prometheus + Grafana to track:

  • node_filesystem_usage_percent{mountpoint="/var/lib/containerd"} (OverlayFS usage).
  • kube_node_status_condition{condition="DiskPressure",status="true"} (DiskPressure alerts).

D. Optimize Container Images#

  • Use multi-stage builds to reduce image size.
  • Avoid storing large assets (e.g., logs, caches) in container layers; use persistent volumes instead.

E. Update EKS & Components#

EKS 1.18 is outdated (EOL: September 2022). Upgrade to newer versions (e.g., 1.28+) for improved ImageGC and containerd stability.

6. Conclusion#

The "Failed to Garbage Collect Required Images" error in EKS 1.18 is a cascading issue caused by OverlayFS exhaustion, blocked ImageGC, and evicted pods. By troubleshooting with kubectl, crictl, and kubelet logs, you can identify and resolve the root cause—whether through manual cleanup, ImageGC reconfiguration, or evicted pod deletion.

Prevent recurrence by allocating sufficient disk space, automating image cleanup, and monitoring disk usage. For long-term stability, upgrade to a supported EKS version to leverage improved garbage collection and container runtime features.

7. References#