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?
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.).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With