Files
poimen-memory/k8s/infra/runner-cleanup-cronjob.yaml
T

122 lines
3.3 KiB
YAML
Raw Normal View History

2026-09-13 14:14:28 +09:00
# CronJob to periodically clean Gitea Actions runner disk space
# Prevents "no space left on device" errors during Docker builds
# Deploy to: kubectl apply -f k8s/infra/runner-cleanup-cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: runner-disk-cleanup
namespace: ci # Adjust to your runner namespace
labels:
app: runner-cleanup
spec:
# Run daily at 2 AM
schedule: "0 2 * * *"
# Keep last 3 successful jobs
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
metadata:
labels:
app: runner-cleanup
spec:
serviceAccountName: runner-cleanup
# Run on node with Gitea Actions runner
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- runner-node # Adjust to your runner node name
containers:
- name: cleanup
image: docker:24
securityContext:
privileged: true # Needed to access Docker daemon
command:
- /bin/sh
- -c
- |
echo "=== Runner disk cleanup at $(date) ==="
df -h /
echo ""
echo "Cleaning Docker..."
docker system prune -af --volumes 2>&1 | tail -5
echo ""
echo "Cleaning Cargo cache..."
rm -rf /root/.cargo/registry/cache 2>/dev/null
rm -rf /root/.cargo/registry/index 2>/dev/null
rm -rf /root/.cargo/git 2>/dev/null
echo ""
echo "Cleaning /tmp..."
rm -rf /tmp/* 2>/dev/null
echo ""
echo "Disk after cleanup:"
df -h /
volumeMounts:
- name: docker-sock
mountPath: /var/run/docker.sock
- name: runner-home
mountPath: /root
volumes:
# Access Docker daemon on host
- name: docker-sock
hostPath:
path: /var/run/docker.sock
# Access runner home directory
- name: runner-home
hostPath:
path: /home/runner # Adjust to your runner home path
restartPolicy: OnFailure
---
# ServiceAccount for cleanup job
apiVersion: v1
kind: ServiceAccount
metadata:
name: runner-cleanup
namespace: ci
---
# Role for cleanup job
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: runner-cleanup
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list"]
---
# RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: runner-cleanup
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: runner-cleanup
subjects:
- kind: ServiceAccount
name: runner-cleanup
namespace: ci