liveBook · Manning

Chapter 18: Batch processing with Jobs and CronJobs

What you will learn in chapter 18 of Kubernetes in Action, Second Edition

The introduction distinguishes continuously running pods from finite workloads and explains when to use a Job or a CronJob.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction distinguishes continuously running pods from finite workloads and explains when to use a Job or a CronJob.

Key terms: finite workload, Job resource, Kubelet, Job, CronJob

18.1 Running tasks with the Job resource

This section contrasts finite tasks with continuously running pods and explains why a Job is preferable to managing a one-off pod yourself.

Key terms: OnFailure restart policy, quiz-data-importer Pod, Deployment, Job object, pod, node

18.1.1 Introducing the Job resource

Introduces Jobs as workloads that finish after their pods succeed, then shows how to create, inspect, suspend, resume, and delete them.

Key terms: Job, pod, completions, Pod template, init container, restartPolicy, OnFailure, Never, STATUS, DURATION

18.1.2 Running a task multiple times

This section explains how Job completions and parallelism control repeated task execution, then shows how to observe a five-completion Job running at most two pods at once.

Key terms: Job, completions, parallelism, Job controller, pods, kubectl apply, Running, Completed, RESTARTS

18.1.3 Understanding how Job failures are handled

Explains how Kubernetes retries failed Job tasks and how retry limits, deadlines, and custom policies can cause a Job to fail.

Key terms: restartPolicy, OnFailure, Never, Kubelet, Job controller, backoff limit, spec.backoffLimit, activeDeadlineSeconds, completions, parallelism

18.1.4 Parameterizing pods in a Job

This section explains how to give pods distinct portions of a batch task, contrasting separate NonIndexed Jobs with one Indexed Job and showing how a completion index can select simple or complex inputs.

Key terms: NonIndexed, Pod template, MONTH, Indexed, completion index, completions, parallelism, JOB_COMPLETION_INDEX, batch.kubernetes.io/job-completion-index, Downward API

18.1.5 Running Jobs with a work queue

This section shows how Jobs can process a container-managed work queue, contrasts coarse and fine parallel processing, and explains why a completed Job does not handle items added later.

Key terms: Job, work queue, work items, containers, coarse parallel processing, completions, parallelism, work item, fine parallel processing, Job controller

18.1.6 Communication between Job’s Pods

This section shows how pods in an Indexed Job can find and communicate with specific peers through a headless Service and DNS.

Key terms: Indexed, headless Service, clusterIP, label selector, job-name, subdomain, DNS, completions, comm-demo-0.demo-service, Kubernetes API server

18.1.7 Sidecar containers in Job pods

Explains why an ordinary sidecar can prevent a Job from completing and how a native sidecar lets the Job finish.

Key terms: sidecar containers, spec.containers, NotReady, initContainers, sidecar container, Completed

18.2 Scheduling Jobs with CronJobs

This section explains why scheduled tasks need a CronJob and how a CronJob creates Jobs that then create pods.

Key terms: Job, suspended state, CronJob, CronJob object, Job template, schedule, CronJob controller, Job controller

18.2.1 Creating a CronJob

Shows how to create a CronJob from a manifest and inspect the Jobs, pods, status, and events it produces.

Key terms: CronJob, schedule, jobTemplate, Job, CronJob controller, Job template, Pod template, label selector, ACTIVE, LAST SCHEDULE

18.2.2 Configuring the schedule

Explains how to read a CronJob schedule, including crontab fields, day-matching behavior, shorthand schedules, and time zones.

Key terms: schedule, crontab format, minute, hour, day of the month, month, Day of month, Day of week, @hourly, @daily

18.2.3 Suspending and resuming a CronJob

Explains how to suspend and resume a CronJob and what happens to Jobs when it is suspended.

Key terms: CronJob, kubectl patch, suspended, Job

18.2.4 Automatically removing finished Jobs

Explains why a CronJob retains only some finished Jobs and how to change its history limits.

Key terms: CronJob controller, successfulJobsHistoryLimit, failedJobsHistoryLimit, Job, pods

18.2.5 Setting a start deadline

Explains how a CronJob start deadline limits late Job creation and prevents a backlog of missed Jobs after controller downtime.

Key terms: startingDeadlineSeconds, CronJob controller, MissSchedule event, TooManyMissedTimes event, missing jobs

18.2.6 Handling Job concurrency

Explains that CronJob runs can overlap by default and that the CronJob spec provides a concurrencyPolicy setting to change this behavior.

Key terms: CronJob controller, Job, ACTIVE column, concurrencyPolicy

18.2.7 Deleting a CronJob and its Jobs

This section explains how deleting a CronJob affects its Jobs and pods, and how to preserve them when removing the CronJob.

Key terms: CronJob, Job, pods, --cascade=orphan, suspend

18.3 Summary

Summarizes how Jobs run tasks to completion, how their pods can divide and coordinate work, and how CronJobs schedule Jobs.

Concepts explained in this chapter

← Chapter 17: Deploying per-node workloads with DaemonSets

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.