Home > Software engineering >  Spin another docker container and pod in kubernetes
Spin another docker container and pod in kubernetes

Time:06-05

I have 3 pods in kubernetes each with separate and single docker container. Each docker container has its own express app.

  1. Pod 1 => Docker Container A
  2. Pod 2 => Docker Container B
  3. 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.

  1. Start another pod in kubernetes.
  2. Initiate Container D
  3. Run the codes and generate output.
  4. Return back the output to Container D.
  5. Container A sends back the response to user.
  6. 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,

  1. Pod A stamp job as JOB.1
  2. Pod A create K8S job with parameter to wait JOB.1 in NATs
  3. 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.

  • Related