>_ IzzyLab

Hands-on task

This task is step 12 of the course “Kubernetes: manifests from Namespace to RBAC”

k8s: Job that runs to completion

medium~11 min

Prepare in /root/job.yaml a Job object (batch/v1) pi: a single container from the busybox:1.36 image computes π with the command awk 'BEGIN { printf "%.5f\n", atan2(0, -1) }' and exits; the pod's restartPolicy is Never. You don't have to write it by hand — it's easier to generate the manifest with a kubectl command and --dry-run=client -o yaml; look at it in the Editor tab. Then run the Job in this sandbox's Kubernetes cluster (kubectl is already configured) and wait until it finishes: 3.14159 must show up in its logs.

What you'll practise:
  • kubernetes
  • job
  • kubectl create
  • dry-run
  • yaml manifests
  • kubectl apply
  • kubectl logs

Topic breakdown

A Job in Kubernetes (API group batch/v1) is a one-off task: a pod starts, does its work and exits — unlike a Deployment, which keeps pods alive forever. For a Job, restartPolicy: Never (or OnFailure) is natural — retries on failure are managed by the Job controller itself via backoff, not by the kubelet. Instead of writing YAML by hand, it's convenient to generate the manifest with an imperative kubectl command and ask it to print the result in client-side dry-run mode (-o yaml) without touching the cluster. A finished Job doesn't disappear: status.succeeded shows the number of successful runs, and the finished pod's logs stay available via kubectl logs.

What's checked

  1. manifest is valid (kubeconform)
  2. the file has a Job pi
  3. restartPolicy = Never
  4. Job pi succeeded in the cluster
  5. the Job's logs show 3.14159

What it looks like