Kubernetes Node Drainer helps to evict pods from nodes before shutdown.
It is a single statically compiled binary in a minimal container (FROM scratch) run as non-root user.
A small binary run as a DaemonSet and listenning for a trigger (e.g. AWS ASG Lifecycle Hook).
When triggered it uses Kubernetes Eviction API to drain the node (just like the kubectl drain command).
The code is prepared for multiple trigger providers if there is a community interest in such functionality, but currently supported triggers are:
The kubedrainer needs to run on every Kubernetes node.
Only 3 steps required:
- Add a ASG lifecycle hook
- Provide access to AWS API
- Deploy the deamonset
You need to configure your Auto Scaling Group (ASG) to wait for singal, before shutting down an instance.
Without the lifecycle hook, the ASG wont wait for the kubedrainer to evict the pods.
CloudFormation fragment that shows the lifecycle hook config:
NodeGroup:
Type: AWS::AutoScaling::AutoScalingGroup
...
NodeGroupLifecycleHook: # for node drainer
Type: AWS::AutoScaling::LifecycleHook
Properties:
AutoScalingGroupName:
Ref: NodeGroup
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING"
HeartbeatTimeout: 360The kubedrainer require access to a small portion of AWS API:
autoscaling:CompleteLifecycleActionautoscaling:DescribeAutoScalingGroupsautoscaling:DescribeAutoScalingInstancesautoscaling:DescribeLifecycleHooks
See an example IAM Role in the examples/iam.yaml
The kubedrainer needs to run on every Kubernetes node.
See an example DaemonSet with RBAC examples/kubernetes/yaml
Feel free to create a GitHub Issue for any questions, bug reports or feature requests, also Pull Requests are welcome, just make sure you discuss any major changes before investing a lot of time.
Install Makefile dependencies:
make initVerify the code:
make verifyBump the version:
make bump-versionTag the release:
make tagWe believe in obvious names. It drains kubernetes nodes. It's kubedrainer.