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)?
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.
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.
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 .
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) 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With