Simple Kubernetes CronJob for System Monitoring

Simple Kubernetes CronJob for System Monitoring

This example demonstrates a straightforward Kubernetes CronJob that periodically runs top to display basic system information.

apiVersion: batch/v1
kind: CronJob
metadata:
  name: basic-system-monitor
spec:
  schedule: "*/10 * * * *"  # Runs every 10 minutes
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: system-monitor
              image: busybox  # Lightweight image with basic utilities
              args:
                - /bin/sh
                - -c
                - "top -bn1"
          restartPolicy: OnFailure

schedule: Runs every 10 minutes (*/10 * * * *).
image: Uses busybox, which includes essential utilities like top.
args: Runs the top -bn1 command to output basic system information once.

Steps to Deploy and Verify

Deploy the CronJob: Apply the YAML configuration:
kubectl apply -f system-health-check.yaml

Verify Execution:
kubectl get cronjob
kubectl get jobs --watch

Check Logs:
kubectl logs pod-name

Remove the CronJob after testing:
kubectl delete cronjob system-health-check