Chapter 7. Managing Specialized Workloads
In Chapter 4, we explored how to launch applications that are supposed to run forever, such as a web server or an app server. In this chapter, we will discuss workloads that are somewhat more specialized—for example, ones that launch terminating processes such as batch jobs, run pods on certain nodes, or manage stateful and noncloud native apps.
7.1 Running a Batch Job
Problem
You want to run a process that runs for a certain time to completion, such as a batch conversion, backup operation, or database schema upgrade.
Solution
Use a Kubernetes job resource to launch and supervise the pod(s) that will carry out the batch process.1
First, define the Kubernetes manifest for the job in a file called counter-batch-job.yaml:
apiVersion:batch/v1kind:Jobmetadata:name:counterspec:template:metadata:name:counterspec:containers:-name:counterimage:busyboxcommand:-"sh"-"-c"-"foriin123;doecho$i;done"restartPolicy:Never
Then launch the job and have a look at its status:
$ kubectl create -f counter-batch-job.yaml job "counter" created $ kubectl get jobs NAME DESIRED SUCCESSFUL AGE counter 1 1 22s $ kubectl describe jobs/counter Name: counter Namespace: default Selector: controller-uid=634b9015-7f58-11e7-b58a-080027390640 Labels: controller-uid=634b9015-7f58-11e7-b58a-080027390640 job-name=counter Annotations: <none> Parallelism: 1 Completions: 1 Start Time: Sat, 12 Aug 2017 13:18:45 +0100 Pods Statuses: 0 Running ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access