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 Answers
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.
keda.sh
? Does it resolve your issue? – PjoterS