Does Kubernetes move pods between nodes or is the Replica Set that recreates the pods?

11/29/2021

I am wondering if Kubernetes can automatically move the pods to another node if that node resources are on critical, or if that happens only for pods managed by Replica Sets?

In particular:

  1. What happens when a bare pod (not managed by Replica Sets or similar) is evicted? Is it moved to another node or it is just removed?
  2. In case it is "moved" to a new node, is it really moved or it is recreated? For example, does its age change?
  3. Is it true that only pods managed by Deployments and Replica Sets are moved/recreated on a new node while bare pods are simply removed in case of resource shortage?
-- collimarco
kubernetes
kubernetes-pod

2 Answers

11/30/2021

A orphan pod will be delete by kubelet/eviction_manager when evicted, no recreation.

No removed, only recreated.

The deploy/replicaset will keep the number of replicas, so a new pod will be created and kube-scheduler will schedule it to a fit node.

-- vincent pli
Source: StackOverflow

11/30/2021
  1. What happens when a bare pod (not managed by Replica Sets or similar) is evicted? Is it moved to another node or it is just removed?

Pod is designed as a relatively ephemeral, disposable entity; when it is evicted, it's deleted by a Kubelet agent running on the node. There is no recreating / moving to the other node, it's just removed (for bare pods). The controllers (like Deployment, StatefulSet, DaemonSet) are responsible for placing the replacement pods.

  1. In case it is "moved" to a new node, is it really moved or it is recreated? For example, does its age change?

As I mentioned in the answer from the previous question, in the Kubernetes architecture pods are designed as relatively ephemeral, disposable entities, so there is no "moving". It's recreated as a "fresh" pod on the same or new node. The age parameter is changed, it's starting counting from the beginning as it is a new pod.

  1. Is it true that only pods managed by Deployments and Replica Sets are moved/recreated on a new node while bare pods are simply removed in case of resource shortage?

Not only pods managed by Deployment/ReplicaSets but it's also true for some other controllers (e.g StatefulSet). When a pod is missing (it's got evicted by resource shortage or there is a rolling update), the controllers are making requests to the Kubernetes Scheduler to roll-out new pods. The bare pods, as answered in the first question, are not recreated.

If you want to read more about this process, check my other answer.

-- Mikolaj S.
Source: StackOverflow