How should a React + Node.js app be split into containers/pods for Kubernetes?

1/28/2018

I read that a pod often only has 1 container.

Does this mean that I should have 2 pods: 1 React and 1 Node.js?

What if I have a web server like nginx running in front of the React frontend? Then React + nginx = 2 containers = 1 Frontend pod and 1 Node.js pod?

-- atkayla
containers
kubernetes
kubernetes-pod

2 Answers

1/28/2018

Kubernetes's smallest deployment unit is Pod. There are some cases like

  • Frontend and NodeJs always scaled together and you want 3 fronted 3 nodejs and sometime later you want 4 nodejs 4 frontend. It is not recommended but you may put these into one pod definition
  • Basically two different containers and not dependent on each other while scaling then you should put these on different pod definitons and expose them as services.

Think about traditional databases and frontend systems. Do you scale the underlying database system while scaling your frontend systems. So When it comes to same pod definition or different pod definitions for multiple containers we should think about scaling and security.

-- Pamir Erdem
Source: StackOverflow

1/28/2018

"pod often only has 1 container". No it doesn't mean that you should have two Pods for your application. You can use two Containers in a Pod.

Each Pod is assigned a unique IP address. Every container in a Pod shares the network namespace, including the IP address and network ports. Containers inside a Pod can communicate with one another using localhost. When containers in a Pod communicate with entities outside the Pod, they must coordinate how they use the shared network resources (such as ports).

If you need to share same Network namespace, you need to keep them in a Pod.

Also, it depends on purpose. You can group multiple process together if they fulfill similar purpose. If an application needs several process running on the same host, you can use multiple containers.

This blog post explains some Use Cases: www.mirantis.com/blog

-- Mir Shahriar Sabuj
Source: StackOverflow