Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gracefully drain a node in EKS?

Sometimes we need to drain nodes in Kubernetes. When I manually set up a k8s cluster, I can drain the specific node then terminate that machine. While in EKS, nodes are under auto scaling group, which means I can't terminate a specific instance(node). If I manually terminate a instance, another instance(node) will be automatically added into eks cluster.

So is there any suggested method to drain a node in EKS?

like image 926
Shengxin Zhang Avatar asked Aug 13 '18 20:08

Shengxin Zhang


People also ask

How do you drain nodes in Kubernetes?

Use kubectl drain to remove a node from service You can use kubectl drain to safely evict all of your pods from a node before you perform maintenance on the node (e.g. kernel upgrade, hardware maintenance, etc.).

How do I clean my EKS cluster?

Cleaning up In order to delete the Ocean cluster, on the Ocean dashboard click Actions, and then “Delete”. Click “Delete Cluster” in the prompt. Next in order to delete your Spot.io Organization, click the blue “Chat” button on far right edge of your Console, and ask the 24/7 Spot.io Tech Support team to delete it.

How do I cancel my EKS node?

Open the Amazon EKS console at https://console.aws.amazon.com/eks/home#/clusters . Choose the cluster that contains the node group to delete. Select the Compute tab. Select the node group to delete, and choose Delete.


1 Answers

These steps should work:

1.) kubectl get nodes

2.) kubectl cordon <node name>

3.) kubectl drain <node name> --ignore-daemonsets

4.) aws autoscaling terminate-instance-in-auto-scaling-group --instance-id <instance-id> --should-decrement-desired-capacity

For step 3, you might need to consider using this instead:

kubectl drain <node name> --ignore-daemonsets --delete-local-data

For AWS autoscaling group, if you have nodes span out to multiple zones, consider delete nodes in each zones instead of all nodes from a single zone.

After the execution of the above commands, check the autoscaling group's desired number. It should decrease automatically. If you are using terraform or other automation framework, don't forget to update your autoscaling group config in your infrastructure script.

like image 147
Steve-Liang Avatar answered Sep 18 '22 11:09

Steve-Liang