Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to migrate the pods automatically to another node in kubernetes?

I am a new cookie to kubernetes . I am wondering if kubernetes have automatically switch the pods to another node if that node resources are on critical.

For example if Pod A , Pod B , Pod C is running on Node A and Pod D is running on Node B. The resources of Node A used by pods would be high. In these case whether kubernetes will migrate the any of the pods running in Node A to Node B.

I have learnt about node affinity and node selector which is used to run the pods in certain nodes. It would be helpfull if kubernetes offer this feature to migrate the pods to another node automatically if resources are used highly.

Can any one know how can we achieve this in kubernetes ?

Thanks -S

like image 827
StackOverFlow Avatar asked Jul 19 '17 11:07

StackOverFlow


People also ask

How do you reschedule pods to different nodes?

Pods are only scheduled once in their lifetime. Once a Pod is scheduled (assigned) to a Node, the Pod runs on that Node until it stops or is terminated. So the answer to your question is “no”, as others had already mentioned: the pod will not be re-scheduled to any other node.

Can containers of a pod be scheduled on different nodes?

You can use a node selector to place specific pods on specific nodes, cluster-wide node selectors to place new pods on specific nodes anywhere in the cluster, and project node selectors to place new pods in a project on specific nodes.

How do you force a pod to run on a specific node?

You can add the nodeSelector field to your Pod specification and specify the node labels you want the target node to have. Kubernetes only schedules the Pod onto nodes that have each of the labels you specify.


1 Answers

Yes, Kubernetes can migrate the pods to another node automatically if resources are used highly. The pod would be killed and a new pod would be started on another node. You would probably want to learn about Quality of Service Classes, to understand which pod would be killed first.

That said, you may want to read about Automatic Horizontal Pod Autoscaling. This may give you more control.

With Horizontal Pod Autoscaling, Kubernetes automatically scales the number of pods in a replication controller, deployment or replica set based on observed CPU utilization (or, with alpha support, on some other, application-provided metrics).

like image 188
rrh Avatar answered Oct 21 '22 18:10

rrh