Skip to content

Instantly share code, notes, and snippets.

@limed
Last active May 8, 2019 23:02
Show Gist options
  • Save limed/2486e84dcbb1098981af076011cfb8db to your computer and use it in GitHub Desktop.
Save limed/2486e84dcbb1098981af076011cfb8db to your computer and use it in GitHub Desktop.
lifecycled handler
[Unit]
Description=Autoscale Lifecycle Daemon
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=on-failure
RestartForceExitStatus=SIGPIPE
RestartSec=30s
TimeoutStopSec=5m
EnvironmentFile=/etc/lifecycled
ExecStart=/usr/bin/lifecycled --cloudwatch-group=/aws/lifecycled --json
[Install]
WantedBy=multi-user.target
#!/bin/bash
set -u
set -x
HOSTNAME=$(curl -fsq http://169.254.169.254/latest/meta-data/hostname)
REGION=$(curl -fqs http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)
CLUSTER_NAME=$(cat /etc/eks/cluster_name)
# Setup kubeconfig
aws eks update-kubeconfig --region "${REGION}" --name "${CLUSTER_NAME}"
export KUBECONFIG="/root/.kube/config"
kubectl cordon "${HOSTNAME}"
kubectl drain "${HOSTNAME}" --ignore-daemonsets --grace-period=30 --force
sleep 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment