I have 3 pods in kubernetes each with separate and single docker container. Each docker container has its own express app.
- Pod 1 => Docker Container A
- Pod 2 => Docker Container B
- Pod 3 => Docker Container C
All this 3 pods interacts with each other via NATS streaming server for pub/sub purposes.
Now, I am looking into how to spin up another pod with a single Docker Container D. The context is, Docker Container A will receive codes from client. I need to run the codes and generate the output.
My thought process is, when Container A received the request.
- Start another pod in kubernetes.
- Initiate Container D
- Run the codes and generate output.
- Return back the output to Container D.
- Container A sends back the response to user.
- Stop Container D and its pod.
Please kindly let me know if there is a better way to implement this course of action. I am out of clue on how to starting another pod in kubernetes from a different container and also different pod.
Thanks in advance!
CodePudding user response:
You need "jobs" kinds. [https://kubernetes.io/docs/concepts/workloads/controllers/job/]
firstly, I assume that you need 1 process per 1 jobs. So,
- Pod A stamp job as JOB.1
- Pod A create K8S job with parameter to wait JOB.1 in NATs
- Pod A send JOB.1 to NATs
once Job process start. it will pull NATs to get JOB.1 todo. Job should terminate ifself once if finish.
However, if I design the service. I perfer create Container D as pool of worker which can scale using HPA based on CPU/memory usage.
Hope this help.