Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
All solutions
    • All solutions for Managed Service for Kubernetes
    • Resolving the `Timed out waiting for the condition` error when mounting a PVC
    • Resolving the `Timed out waiting for the condition` error when mounting a volume with a large number of files
    • Hosts of the Managed Service for Kubernetes node groups stay in the `RECONCILING` status for a long time
    • Cyclical restarts of the `kube-dns-autoscaler` pod
    • Cannot reduce the number of nodes in a Managed Service for Kubernetes group
    • Cannot increase the number of nodes in a Managed Service for Kubernetes group
    • Resolving the `Multi-Attach error for volume` error
    • Resolving the `DEADLINE_EXCEEDED` error
    • Troubleshooting time synchronization issues on Managed Service for Kubernetes cluster nodes
    • Troubleshooting DNS name resolving issues in Managed Service for Kubernetes
    • Resolving the `0/10 nodes are available - node(s) had untolerated taint` error
    • The cluster remains in the `STARTING` status for too long
    • Cluster pods remain in the `PENDING` status for too long
    • Troubleshooting HPA issues in Managed Service for Kubernetes
    • Resolving the `Can't use allocation_policy.locations.subnet_id together with node_template.network_interface_specs` error
    • Troubleshooting issues when mounting volumes to Managed Service for Kubernetes cluster pods using Container Storage Interface for S3
    • Managed Service for Kubernetes cluster remains `STARTING` for too long after renaming
    • How to add and update Linux SSH keys on Managed Service for Kubernetes node group hosts
    • How to assign static external IP addresses to Managed Service for Kubernetes cluster nodes
    • How to provide Kubernetes nodes with internet access
    • How to create an internal Ingress controller
    • How to set up autodeletion of old images from Managed Service for Kubernetes nodes
    • How to find out the external IP address of a Managed Service for Kubernetes node
    • How to use Certificate Manager certificates in load balancers or in Managed Service for Kubernetes
    • How to change the time zone on Managed Service for Kubernetes cluster nodes
    • How to find out the ephemeral storage size for a Managed Service for Kubernetes node

In this article:

  • Case description
  • Solution
  • If nothing helped
  1. Managed Service for Kubernetes
  2. How to set up autodeletion of old images from Managed Service for Kubernetes nodes

How to set up autodeletion of old images from Managed Service for Kubernetes nodes

Written by
Yandex Cloud
Updated at December 17, 2025
  • Case description
  • Solution
  • If nothing helped

Case descriptionCase description

When using a Managed Service for Kubernetes cluster, you see that the cluster nodes are running low on disk space. Cluster nodes periodically run out of available disk space.

To free up disk space, you need to set up autodeletion of old images from your Managed Service for Kubernetes nodes.
You need to change the garbage collection configuration in Kubernetes to clean up old images, e.g., by setting the image-gc-low-threshold and image-gc-high-threshold values.

SolutionSolution

The garbage collection in Managed Service for Kubernetes has these standard settings:

  • --image-gc-high-threshold (85%): Disk usage percentage. Reaching the specified value triggers image garbage collection.
  • --image-gc-low-threshold (80%): Disk usage percentage below which the image garbage collection is not triggered.

The setting values are specified in accordance with the Kubernetes developer guide.

Old images are cleaned up automatically. Therefore, when the disk usage reaches 85%, kubelet will try to clean up the garbage to 80%.

For autodeletion of old images from cluster nodes, you can also use these specifications:

Specification for Docker Engine
apiVersion: batch/v1
kind: CronJob
metadata:
  name: docker-image-cleanup
spec:
  schedule: "0 0 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: docker-image-cleanup
            image: alpine:latest
            command:
            - /bin/sh
            - -c
            - >
              echo y | docker image prune -f
            volumeMounts:
            - name: docker-socket
              mountPath: /var/run/docker.sock
          volumes:
          - name: docker-socket
            hostPath:
              path: /var/run/docker.sock
          restartPolicy: OnFailure
Specification for Containerd
apiVersion: v1
kind: ConfigMap
metadata:
  name: imagecleanupconfig
  namespace: default
  labels:
    component: imagecleanup
data:
  # removes all images unused by a running container
  cronjobs: 0 0 * * * crictl rmi --prune 2>&1
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: imagecleanup
  namespace: default
spec:
  selector:
    matchLabels:
      component: imagecleanup
  template:
    metadata:
      labels:
        component: imagecleanup
    spec:
      volumes:
        - name: containerd
          hostPath:
            path: /var/run/containerd/containerd.sock
            type: Socket
        - name: imagecleanupconfig
          configMap:
            name: imagecleanupconfig
      containers:
        - name: imagecleanup
          image: alpine:latest
          imagePullPolicy: Always
          env:
            - name: CRICTL_VERSION
              value: v1.20.0
            - name: CONTAINER_RUNTIME_ENDPOINT
              value: unix:///var/run/containerd/containerd.sock
            - name: IMAGE_SERVICE_ENDPOINT
              value: unix:///var/run/containerd/containerd.sock
          # details of the command:
          # - install crictl
          # - add a cron job from the config map
          # - execute crond in the foregroud
          command:
            [
              "sh",
              "-c",
              "wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$CRICTL_VERSION/crictl-$CRICTL_VERSION-linux-amd64.tar.gz && tar zxvf crictl-$CRICTL_VERSION-linux-amd64.tar.gz -C /usr/local/bin && crontab /config/cronjobs && crond -f -d 8",
            ]
          resources:
            requests:
              cpu: 100m
              memory: 50Mi
          volumeMounts:
            - name: containerd
              mountPath: /var/run/containerd/containerd.sock
            - name: imagecleanupconfig
              mountPath: /config
---

If nothing helpedIf nothing helped

If the above actions did not help, create a support ticket. Provide the following information in your ticket:

  1. Managed Service for Kubernetes cluster ID.
  2. Issue description.

Was the article helpful?

Previous
How to create an internal Ingress controller
Next
How to find out the external IP address of a Managed Service for Kubernetes node
© 2025 Direct Cursus Technology L.L.C.