What is difference between Kubernetes Jobs & Deployments
Asked Answered
L

2

11

I see that Kubernetes Job & Deployment provide very similar configuration. Both can deploy one or more pods with certain configuration. So I have few queries around these:

  • Is the pod specification .spec.template different in Job & Deployment?
  • What is difference in Job's completions & Deployment's replicas?
  • If a command is run in a Deployment's only container and it completes (no server or daemon process containers), the pod would terminate. The same is applicable in a Job as well. So how is the pod lifecycle different in either of the resources?
Lombardi answered 24/8, 2021 at 11:32 Comment(1)
simply put: deployments are used for services that are expected to be up and running continuously. think webservers, databases, etc. jobs/cronjobs are meant for tasks that are meant to be run and exit after they have finished. think: database backups, etcs.Cubature
S
17

Many resources in Kubernetes use a Pod template. Both Deployments and Jobs use it, because they manage Pods.

Controllers for workload resources create Pods from a pod template and manage those Pods on your behalf.

PodTemplates are specifications for creating Pods, and are included in workload resources such as Deployments, Jobs, and DaemonSets.

The main difference between Deployments and Jobs is how they handle a Pod that is terminated. A Deployment is intended to be a "service", e.g. it should be up-and-running, so it will try to restart the Pods it manage, to match the desired number of replicas. While a Job is intended to execute and successfully terminate.

Stereochemistry answered 24/8, 2021 at 15:57 Comment(0)
F
3

Regarding spec.template: both Job and Deployment would include a similar definition. See: https://v1-21.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#podtemplate-v1-core

Job completions and parallelism lets you split a task in sub-tasks. See https://kubernetes.io/docs/concepts/workloads/controllers/job/#parallel-jobs , https://kubernetes.io/docs/tasks/job/indexed-parallel-processing-static/ . Replicas in a Deployment would not offer this.

In a Deployment, the default restartPolicy of your Pod is set Always. In a Job: Never. A job is not meant to restart your container once it would have exited. A deployment is not meant to exit.

Fishnet answered 24/8, 2021 at 11:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.