Skip to main content

termination-handler

PyPI PyPI - License

About

termination-handler handles termination notices on spot/preemptible instances.

As an example, if deployed on a Kubernetes cluster and a termination notice is issued by the cloud provider, termination-handler drains the node it is running on before the node is taken away by the cloud provider.

Inspired by pusher/k8s-spot-termination-handler for AWS, termination-handler surges from the need to operate the same tooling in various distinct environments (providers, orchestrators...)

Features

  • Supports multiple cloud providers (AWS, GCP).
  • Supports multiple handlers (Kubernetes, Nomad, Slack).
  • Small and extensible.

Documentation

TBD

Usage

Deploy to Kubernetes

A K8s docker image is available at dgzlopes/termination-handler-k8s and sample Kubernetes manifests are available in the deploy/k8s folder.

To deploy in clusters using RBAC, please apply all of the manifests (Daemonset, ClusterRole, ClusterRoleBinding and ServiceAccount) in the deploy/k8s folder but uncomment the serviceAccountName in the Daemonset.

Requirements

For termination-handler to schedule correctly; you will need an identifying label on your spot/preemptible instances.

We add a label node-role.kubernetes.io/spot-worker to our spot/preemptible instances and hence this is the default value in the node selector of the Daemonset.

nodeSelector:
  "node-role.kubernetes.io/spot-worker": "true"

To achieve this, add the following flag to your Kubelet:

--node-labels="node-role.kubernetes.io/spot-worker=true"

Configuration

To define any custom parameters to the drain command you can use DRAIN_PARAMETERS environment property. If not defined, default parameters are --grace-period=120 --force --ignore-daemonsets.

env:
  - name: DRAIN_PARAMETERS
    value: '--grace-period=120 --force --ignore-daemonsets --delete-local-data'

Deploy to Nomad

A Nomad docker image is available at dgzlopes/termination-handler-nomad.

TBD

Demo mode

The main way to use termination-handler is waiting for the termination notice from the cloud provider. However, termination-handler comes with a demo mode that is can simulate the notice. When deployed it will identify your cloud provider and run your handlers.

To activate termination-handler demo mode on Kubernetes, you can use DEMO_TERMINATION_HANDLER environment property.

env:
  - name: DEMO_TERMINATION_HANDLER
    value: True

Other handlers

Slack

Sends a notification message to a specific channel when a termination notice is issued.

How to contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
  3. Write a test which shows that the bug was fixed or that the feature works as expected.
  4. Send a pull request and bug me until it gets merged and published.

Some things that would be great to have:

  • Support for Execution handler (certain command or task)
  • Support for notifications (Datadog..)
  • Option to omit selected cloud provider discovery.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

termination-handler-0.0.5.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

termination_handler-0.0.5-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file termination-handler-0.0.5.tar.gz.

File metadata

  • Download URL: termination-handler-0.0.5.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.9.0b1+

File hashes

Hashes for termination-handler-0.0.5.tar.gz
Algorithm Hash digest
SHA256 b1cb90496aed17e98a8a3550fe7a7cbd3f831410f192831bb96b9d71bf04100b
MD5 9aa6d15e26b63553676bf8ed6cfb63c7
BLAKE2b-256 dd527187243e51d1f50b34836f521bc6719f8df3ea48f614674e01c7668b8301

See more details on using hashes here.

File details

Details for the file termination_handler-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: termination_handler-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.9.0b1+

File hashes

Hashes for termination_handler-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 01c357ba9fc632efe8b013d4342cdd35666d845745bd3f827ccdfac3b53dbe33
MD5 07915311a83ff0ef8e286578c3bdd0f2
BLAKE2b-256 142c989cc81dc258864d33c6e7a007b68273da7c0cee17acb32bff192a177ead

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page