Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Forked from alexeldeib/manifests.yaml
Created July 3, 2023 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilangvperdana/5d386c161f22ad99537408c1ae5faf11 to your computer and use it in GitHub Desktop.
Save gilangvperdana/5d386c161f22ad99537408c1ae5faf11 to your computer and use it in GitHub Desktop.
CRICTL IMAGE CLEANUP on K8S
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
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment