Home > OS >  Run different replica count for different containers within same pod
Run different replica count for different containers within same pod

Time:02-28

I have a pod with 2 closely related services running as containers. I am running as a statefulset and have set replicas as 5. So 5 pods are created with each pod having both the containers. Now My requirement is to have the second container run only in 1 pod. I dont want it to run in 5 pods. But my first service should still run in 5 pods. Is there a way to define this in the deployment yaml file for Kubernetes? Please help.

CodePudding user response:

a "pod" is the smallest entity that is managed by kubernetes, and one pod can contain multiple containers, but you can only specify one pod per deployment/statefulset, so there is no way to accomplish what you are asking for with only one deployment/statefulset.

however, if you want to be able to scale them independently of each other, you can create two deployments/statefulsets to accomplish this. this is imo the only way to do so.

see https://kubernetes.io/docs/concepts/workloads/pods/ for more information.

CodePudding user response:

Containers are like processes,

Pods are like VMs,

and Statefulsets/Deployments are like the supervisor program controlling the VM's horizontal scaling.

The only way for your scenario is to define the second container in a new deployment's pod template, and set its replicas to 1, while keeping the old statefulset with 5 replicas.

  • Related