Drains Kubernetes nodes after they reach the specified best-before age. To be used together with an autoscaler so that the node will get replaced with a fresh one when there is demand.
$ gem build k8s_node_descale.gemspec
$ gem install k8s_node_desacale*.gem
$ k8s-node-descale
$ docker build -t descale --build-arg KUBE_VERSION=1.11.1 .
$ docker run -t descale
$ KUBE_VERSION=1.11.1 docker-compose run -rm
Usage:
k8s-node-descale [OPTIONS]
Drains Kubernetes nodes after they reach the specified best-before date.
Options:
--kubectl PATH specify path to kubectl (default: $PATH)
--kube-config PATH Kubernetes config path (default: $KUBECONFIG)
--max-age DURATION maximum age of server before draining and terminating (default: $MAX_AGE, or "3d")
--max-nodes COUNT drain maximum of COUNT nodes per cycle (default: $MAX_NODES_COUNT, or 1)
--check-period SCHEDULE run periodically, example: --every 1h (default: $CHECK_PERIOD)
--dry-run perform a dry-run, doesn't drain or terminate any instances. (default: $DRY_RUN, or false)
-h, --help print help
You can use the --check-period
option to let the program do its own scheduling or deploy it as a cron job.
The Kubernetes credentials lookup order is:
--kube-config
option orKUBECONFIG
environment variable- "in-cluster-configuration" when running on a Kubernetes node (
KUBERNETES_SERVICE_HOST
andKUBERNETES_SERVICE_PORT_HTTPS
environment variables,/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
and/var/run/secrets/kubernetes.io/serviceaccount/token
configuration files)
Bug reports and pull requests are welcome on GitHub at https://github.com/kontena/k8s-node-descale