kubedrainer

module
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2021 License: Apache-2.0

README

kubedrainer

Build Status Binary Container Go Report Card

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.

How it works

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).

Supported Triggers

The code is prepared for multiple trigger providers if there is a community interest in such functionality, but currently supported triggers are:

Usage

The kubedrainer needs to run on every Kubernetes node.

AWS

Only 3 steps required:

  1. Add a ASG lifecycle hook
  2. Provide access to AWS API
  3. Deploy the deamonset
Lifecycle Hook

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: 360
IAM Role

The kubedrainer require access to a small portion of AWS API:

  • autoscaling:CompleteLifecycleAction
  • autoscaling:DescribeAutoScalingGroups
  • autoscaling:DescribeAutoScalingInstances
  • autoscaling:DescribeLifecycleHooks

See an example IAM Role in the examples/iam.yaml

Deployment as a Daemonset

The kubedrainer needs to run on every Kubernetes node.

See an example DaemonSet with RBAC examples/kubernetes/yaml

Contribution

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.

The name

We believe in obvious names. It drains kubernetes nodes. It's kubedrainer.

Directories

Path Synopsis
cmd
internal
pkg
drainer
Package drainer is mostly transplanted from kubectl See: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/drain/drain.go
Package drainer is mostly transplanted from kubectl See: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/drain/drain.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL