Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch Processing on Kubernetes

Anyone here have experience about batch processing (e.g. spring batch) on kubernetes ? Is it good idea ? How to prevent batch processing process same data if we use kubernetes auto scaling feature ? Thank you.

like image 240
Daniel Setiawan Avatar asked Mar 30 '20 04:03

Daniel Setiawan


People also ask

Is Kubernetes good for batch processing?

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 deploy system processes on Kubernetes?

Once you have a running Kubernetes cluster, you can deploy your containerized applications on top of it. To do so, you create a Kubernetes Deployment configuration. The Deployment instructs Kubernetes how to create and update instances of your application.

Can 2 pods communicate in Kubernetes?

Kubernetes assumes that pods can communicate with other pods, regardless of which host they land on. Kubernetes gives every pod its own cluster-private IP address, so you do not need to explicitly create links between pods or map container ports to host ports.


1 Answers

Anyone here have experience about batch processing (e.g. spring batch) on kubernetes ? Is it good idea ?

For Spring Batch, we (the Spring Batch team) do have some experience on the matter which we share in the following talks:

  • Cloud Native Batch Processing on Kubernetes, by Michael Minella
  • Spring Batch on Kubernetes, by me.

Running batch jobs on kubernetes can be tricky:

  • pods may be re-scheduled by k8s on different nodes in the middle of processing
  • cron jobs might be triggered twice
  • etc

This requires additional non-trivial work on the developer's side to make sure the batch application is fault-tolerant (resilient to node failure, pod re-scheduling, etc) and safe against duplicate job execution in a clustered environment.

Spring Batch takes care of this additional work for you and can be a good choice to run batch workloads on k8s for several reasons:

  • Cost efficiency: Spring Batch jobs maintain their state in an external database, which makes it possible to restart them from the last save point in case of job/node failure or pod re-scheduling
  • Robustness: Safe against duplicate job executions thanks to a centralized job repository
  • Fault-tolerance: Retry/Skip failed items in case of transient errors like a call to a web service that might be temporarily down or being re-scheduled in a cloud environment

I wrote a blog post in which I explain all these aspects in details with code examples. You can find it here: Spring Batch on Kubernetes: Efficient batch processing at scale

How to prevent batch processing process same data if we use kubernetes auto scaling feature ?

Making each job process a different data set is the way to go (a job per file for example). But there are different patterns that you might be interested in, see Job Patterns from k8s docs.

like image 168
Mahmoud Ben Hassine Avatar answered Oct 27 '22 02:10

Mahmoud Ben Hassine