Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes - identical jobs, different parameters

Tags:

kubernetes

What's the easiest way to run a configurable number of identical jobs on Kubernetes but give each of them different parameters (like job number)?

like image 228
pstobiecki Avatar asked Jan 27 '17 11:01

pstobiecki


People also ask

Can Kubernetes job have multiple pods?

To execute and manage a batch task on your cluster, you can use a Kubernetes Job. You can specify the maximum number of Pods that should run in parallel as well as the number of Pods that should complete their tasks before the Job is finished. A Job can also be used to run multiple Pods at the same time.

Can we run containers of same pod on different nodes?

Each Pod contains one container of the corresponding application. This allows you to scale both tiers (the web app and the database) independently from each other. Whether the various Pods run on the same node or on different nodes is not something that you would worry too much about, in most cases.

How do two containers in the same pod communicate?

Multiple containers in the same Pod share the same IP address. They can communicate with each other by addressing localhost . For example, if a container in a Pod wants to reach another container in the same Pod on port 8080, it can use the address localhost:8080 .

Can we have similar container in pod?

Yes, you can add multiple container with same image. The containers object must contain: name: Name of the container. It must be a DNS_LABEL and be unique within the pod.


1 Answers

1) You could either just have a template job and use bash expansions to have multiple job specifications based of that initial template.

As shown in the official Parallel Processing using Expansions user guide:

mkdir ./jobs
for i in apple banana cherry
do
  cat job.yaml.txt | sed "s/\$ITEM/$i/" > ./jobs/job-$i.yaml
done
kubectl create -f ./jobs

2) Or you could create a queue and have a specified number of parallel workers/jobs to empty the queue. The contents of the queue would then be the input for each worker and Kubernetes could spawn parallel jobs. That's best described in the Coarse Parallel Processing using a Work Queue user guide.


  • The first approach is simple and straight forward but lacks flexibility
  • The second requires a message queue as "overhead" but you'll gain flexibility
like image 150
pagid Avatar answered Sep 28 '22 09:09

pagid