Deleting Log Files inside other Pods Using CronJob
apiVersion: batch/v1
kind: CronJob
metadata:
name: delete-server-log
namespace: <namespace>
spec:
schedule: "*/5 * * * *" # Runs every 5 minutes
jobTemplate:
spec:
template:
spec:
containers:
- name: <pod-name>
image: <image>:<tag>
args:
- /bin/sh
- -c
- date=$(date +\%Y-\%m-\%d_\%H-\%M-\%S); echo "Hello from the Kubernetes CronJob!" > /Log/delete-$date.txt
restartPolicy: OnFailure
imagePullSecrets:
- secret1
- secret2
securityContext:
runAsUser: 0 # Run as root