0
votes

I'm wondering if there is an option to execute the task from POD? So when I have POD which is, for example, listening for some requests and on request will delegate the task to other POD(worker POD). This worker POD is not alive when there are no jobs to do and if there is more than one job to do more PODs will be created. After the job is done "worker PODs" will be stopped. So worker POD is live during one task then killed and when new task arrived new worker POD is started. I hope that I described it properly. Do you know if this is possible in Kubernetes? Worker POD start may be done by, for example, rest call from the main POD.

1
You wrote this question in very chaotic way. Could specify what exactly you want, some use case, scenario? When you create a job, this job will create pod to execute task from job. You want to create some kind of monitoring mechanism?PjoterS
you could use keda.sh to scale deployments to zero and have them scale up on some metric like "number of messages in bus".Markus Dresch
Hi @PjoterS . Sorry I will try to describe it better. So i have one POD with, for example, Spring app. Then as a user i sent rest request to this Spring app. But this app is not processing my request. I want to have worker pods. But i wanted have this worker pods created on demand. So if three rest requests will be sent then also three workers need to be created. Worker will work only on one job and then will be terminated. Is it possible in kubernetes?skoczo
@MarkusDresch i think that this is what i need. I will check this. Thanksskoczo
@skoczo did you use keda.sh? Does it resolve your issue?PjoterS

1 Answers

0
votes

There are few ways to achieve this behavior.

Pure Kubernetes Way

This solution requires ServiceAccount configuration. Please take a loot at Kubernetes documentation Configure Service Accounts for Pods.

Your application service/pod can handle different custom task. Applying specific serviceaccount to your pod in order to perform specific task is the best practice. In kubernetes using service account with predefined/specified RBAC rules allows you to handle this task almost out of the box.

The main concept is to configure specific RBAC authorization rules for specific service account by giving different permission (get,list,watch,create) to different Kubernetes resources like (pod,jobs).

In this scenario working pod is waiting for incoming request, after it receives specific request it can perform specific task against kubernetes api.

This can be extend i.e. by using sidecar container inside your working pod. More details about sidecar concept can be found in this article.

Create custom controller

Another way to achieve your goal is to use Custom Controller.

Example presented in Extending the Kubernetes Controller article is showing how custom controller watch kubernetes api in order to instrument underling worker pod (watching kubernetes configuration for any changes and then deletes corresponding pods). In your setup, such controller could watch your api for waiting/not processed request and perform additional task like kubernetes job creation inside k8s cluster.

Using existing solution like Job Processing Using a Work Queue.