diff --git a/README.md b/README.md index 3cb7ca2..1b05142 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,15 @@ 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`. +```yaml +env: + - name: DRAIN_PARAMETERS + value: '--grace-period=120 --force --ignore-daemonsets --delete-local-data' +``` + ## Related - [K8s Spot Rescheduler](https://github.com/pusher/k8s-spot-rescheduler): Move nodes from on-demand instances to spot instances when space is available. diff --git a/deploy/daemonset.yaml b/deploy/daemonset.yaml index 3b3e03d..61e6c63 100644 --- a/deploy/daemonset.yaml +++ b/deploy/daemonset.yaml @@ -23,6 +23,9 @@ spec: valueFrom: fieldRef: fieldPath: spec.nodeName + # Parameters to drain commmand can be adjusted + - name: DRAIN_PARAMETERS + value: '--grace-period=120 --force --ignore-daemonsets' resources: requests: cpu: 5m diff --git a/docker_entrypoint.py b/docker_entrypoint.py index c9f3d69..395df21 100644 --- a/docker_entrypoint.py +++ b/docker_entrypoint.py @@ -13,6 +13,8 @@ def main(): node_name = getenv('NODE_NAME') + drain_parameters = getenv('DRAIN_PARAMETERS', '--grace-period=120 --force --ignore-daemonsets') + print('Watching for termination notice on node %s' % node_name) counter = 0 @@ -22,9 +24,8 @@ def main(): "http://169.254.169.254/latest/meta-data/spot/termination-time" ) if response.status_code == 200: - kube_command = ['kubectl', 'drain', node_name, - '--grace-period=120', '--force', - '--ignore-daemonsets'] + kube_command = ['kubectl', 'drain', node_name] + kube_command += drain_parameters.split() print("Draining node: %s" % node_name) result = call(kube_command)