Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubectl drain and rolling update, downtime

Does kubectl drain first make sure that pods with replicas=1 are healthy on some other node?
Assuming the pod is controlled by a deployment, and the pods can indeed be moved to other nodes. Currently as I see it only evict (delete pods) from the nodes, without scheduling them first.

like image 687
user3599803 Avatar asked Dec 15 '19 11:12

user3599803


People also ask

How do I update Kubernetes without downtime?

Updating an application In Kubernetes this is done with rolling updates. Rolling updates allow Deployments' update to take place with zero downtime by incrementally updating Pods instances with new ones. The new Pods will be scheduled on Nodes with available resources.

How does rolling update work in Kubernetes?

RollingUpdate implements automated, rolling updates for the Pods in the StatefulSet. RollingUpdate causes the controller to delete and recreate each of its Pod, and each Pod one at a time. It waits until an updated Pod is running and ready before to updating its predecessor.

What is zero downtime in Kubernetes?

Kubernetes has promoted zero-downtime updates of deployed models. In other words, the modeling service would not be interrupted by the update and it will continue to process requests without error. Updates are performed in a staged manner to ensure that the application is not impacted.

How does kubectl rollout restart work?

Kubectl rollout restart enables you to upload new applications to the Kubernetes cluster and specify a restart policy. If your application fails, it automatically restarts so you can get your work done.


1 Answers

In addition to Suresh Vishnoi answer:

If PodDisruptionBudget is not specified and you have a deployment with one replica, the pod will be terminated and then new pod will be scheduled on a new node.

To make sure your application will be available during node draining process you have to specify PodDisruptionBudget and create more replicas. If you have 1 pod with minAvailable: 30% it will refuse to drain with following error:

error when evicting pod "pod01" (will retry after 5s): Cannot evict pod as it would violate the pod's disruption budget.

Briefly that's how draining process works:

As explained in documentation kubectl drain command "safely evicts all of your pods from a node before you perform maintenance on the node and allows the pod’s containers to gracefully terminate and will respect the PodDisruptionBudgets you have specified”

Drain does two things:

  1. cordons the node- it means that node is marked as unschedulable, so new pods cannot be scheduled on this node. Makes sense- if we know that node will be under maintenance there is no point to schedule a pod there and then reschedule it on another node due to maintenance. From Kubernetes perspective it adds a taint to the node: node.kubernetes.io/unschedulable:NoSchedule

  2. evicts/ deletes the pods- after node is marked as unschedulable it tries to evict the pods that are running on the node. It uses Eviction API which takes PodDisruptionBudgets into account (if it's not supported it will delete pods). It calls DELETE method to K8S but considers GracePeriodSeconds so it lets a pod finish it's processes.

like image 107
kool Avatar answered Sep 20 '22 11:09

kool