How do I schedule the same pod on different nodes using kubectl scale?

11/16/2016

New to kubernetes. Can I use kubectl scale --replicas=N and start pods on different nodes?

-- BDD
kubectl
kubernetes

2 Answers

11/16/2016

By default the scheduler attempts to spread pods across nodes, so that you don't have multiple pods of the same type on the same node. So there's nothing special required if you're just aiming for best-effort pod spreading.

If you want to express the requirement that the pod must not run on a node that already has a pod of that type on it you can use pod anti-affinity, which is currently an Alpha feature.

If you want to ensure that all nodes (or all nodes matching a certain selector) have that pod on them you can use a DaemonSet.

-- Pixel Elephant
Source: StackOverflow

11/16/2016

Scaling a Deployment (or RC) tells controller-manager to create more pods, new pods are then subject to scheduling. K8S scheduler will attempt to find most reasonable placement to schedule your pods to. This does not guarantee that pods will launch on different nodes, but makes it a rather likely scenario, if you have the required resources. Unfortunately it also means that if all pods can fit on one node, there are situations where scheduler might actually do just that (ie. all other nodes in unschedulable state for some reason). If that happens, the pods will not reschedule when conditions change.

To have a solid guarantee that pods wil not get colocated on the same node you have two options:

  • legacy hack : define a hostPort in your pod template. As given host port is a resource that can be assigned only once per node, your pods will never exist more then once per node
  • alpha feature : you can look into Pod AntiAffinity, quite early and not really battle proven yet

First one has a dissadvantage - you can never have more then one pod of this type per node, so it ie. affects rolling deployments and limits your capacity for scaling (you can never have more active pods then number of nodes)

-- Radek 'Goblin' Pieczonka
Source: StackOverflow