Package: eks-node-migrator
EKS Node MigratorEKS Node Migrator is a utility to gracefully drain / cordon self-managed EKS nodes in an EKS cluster.EKS Node MigratorIntroRequirementsInstallationFrom PyPiFrom sourceUsageConfigurationExamplesDockerLicenseIntroEKS Node Migrator is a utility for gracefully draining the desired nodegroups in an EKS cluster in a rolling manner. This tool is specifically focused on scanerio where additional nodegroups are provisioned in the clusters and workload is to be shifted from the older nodegroups to the newer ones. It can be specially useful in the case when a cluster is provisioned with new nodegroups based on SPOT instances and older nodegroups are to be depcreated. This tool will only take care of node drain / cordon process, scaling down the ASGs and / or removing the nodes from the cluster is not part of the process at the momment.To achieve this, it performs the following actions:Finds a list of desired ASGs and node hostnames via provided nodegroup and cluster nameStores the node details on which the target 'action' is to be performedPerform drain / cordon operations on the stored list of nodes with provided nodegroup in a rolling mannerDuring the drain/cordon process, the tool keeps checking the cluster workload health (POD health), bad health for longer duration halts the processEnsures the ASGs are healthy and that the new nodes have joined the EKS clusterThe tool is designed to work on one nodegroup in the cluster at a timeThis tool is inspired byhttps://github.com/hellofresh/eks-rolling-updateRequirementskubectlinstalledKUBECONFIGenvironment variable set, or config available in${HOME}/.kube/configper defaultAWS credentialsconfiguredInstallationFrom PyPi$ mkdir ~/apps
$ mkdir ~/apps/eks-node-migrator
$ cd ~/apps/eks-node-migrator
$ virtualenv .env
$ source .env/bin/activate
(.env)$ pip install eks-node-migrator

$ cd /usr/local/bin
$ sudo ln -s ~/apps/myutil/.env/bin/eks_node_migrator.pyFrom sourcevirtualenv -p python3 venv
source venv/bin/activate
pip3 install -r requirements.txtUsageusage: eks_node_migrator.py [-h] --cluster_name CLUSTER_NAME --nodegroup NODEGROUP --action ACTION

The tool to perform eks node drain/cordon ops

optional arguments:
  -h, --help            show this help message and exit
  --cluster_name CLUSTER_NAME, -c CLUSTER_NAME
                        the cluster name to perform drain/cordon operation on
  --nodegroup NODEGROUP, -ng NODEGROUP
                        the nodegroup name to perform drain/cordonupdate on
  --action ACTION, -a ACTION
                        the action to be performed i.e. drain or cordonExample:eks_node_migrator.py -c my-eks-cluster -ng monitoring -a cordon

eks_node_migrator.py -c my-eks-cluster -ng monitoring -a drainConfigurationEnvironment VariableDescriptionDefaultAWS_DEFAULT_REGIONDefault AWS Region to execute the script oneu-west-1BETWEEN_NODES_WAITNumber of seconds to wait after removing a node before continuing on0K8S_CONTEXTContext from the Kubernetes config to use. If this is left undefined the current-context is usedNoneK8S_PROXY_BYPASSSet to true to ignore HTTPS_PROXY and HTTP_PROXY and disable use of any configured proxy when talking to the K8S APIFalseEXTRA_DRAIN_ARGSAdditional space-delimited args to supply to thekubectl drainfunction, e.g--force=true. Seekubectl drain -h""ExamplesApply Changes$ python eks_node_migrator.py --cluster_name YOUR_EKS_CLUSTER_NAME --nodegroup WORKER-NG-01 --action cordonEnvironment VariableIn order to modify default values for env varibales, please use it by exporting it the as follow:$ export  BETWEEN_NODES_WAIT=30Configure tool via.envfileRather than using environment variables, you can use a.envfile within your working directory to load
updater settings. e.g:$ cat .env
BETWEEN_NODES_WAIT=30DockerPlease feel free to use the includedDockerfileto build your own image.makedocker-distversion=1.0.DEVAfter building the image, run using the commanddockerrun-ti--rm\-eAWS_DEFAULT_REGION\-eAWS_PROFILE\-v"${HOME}/.aws:/root/.aws"\-v"${HOME}/.kube/config:/root/.kube/config"\eks-node-migrator:latest\-cbeta-spot-dev-sre-eks\-ngworker-ng-spot-1\-adrainPass in any additional environment variables and options as described elsewhere in this file.LicenseThis project is licensed under the Apache 2.0 License - see theLICENSEfile for details