Skip to content

Instantly share code, notes, and snippets.

@juliohm1978
juliohm1978 / drain.sh
Last active March 13, 2024 14:10
A bash alternative to kubectl drain
#!/bin/bash
##
## This aims to be an alternative to `kubectl drain NODE`, overcoming
## some of its limitations. A GitHub issue was closed a while ago
## without any solution or alternatives.
##
## https://github.com/kubernetes/kubernetes/issues/48307
##
## Even though `kubectl drain` respects PDBs defined by the user,
version: '3'

services:
  a:
    image: ubuntu
    command: sleep 999

  b:
 image: ubuntu
# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
k8s-master01-prd-20190426
k8s-master02-prd-20190426
k8s-etcd01-prd-20190426
k8s-etcd02-prd-20190426
k8s-etcd03-prd-20190426
k8s-etcd04-prd-20190426
k8s-etcd05-prd-20190426
k8s-node01-prd-20190426
# /usr/bin/ansible-playbook cluster.yml -b -i inventory/inventory.ini
PLAY [localhost] ***************************************************************
TASK [Check ansible version >=2.7.8] *******************************************
Thursday 02 May 2019 20:59:59 -0300 (0:00:00.029) 0:00:00.029 **********
ok: [localhost] => {
"changed": false,
"msg": "All assertions passed"
}
@juliohm1978
juliohm1978 / k8s-drain.sh
Last active March 13, 2024 14:12
Drains a Kubernetes node using "rollout restart" instead "kubectl drain". See comments for motiviation and usage.
#!/bin/bash
NODE_NAME=$1
ROLLOUT_CMD=$2
if [[ "$NODE_NAME" == "" ]]; then
echo "
USAGE: ./drain.sh <NODE_NAME>
Drains a node from its Deployments/Stateful set pods.