Giter Site home page Giter Site logo

kubernetes_restart_nodes_automation's Introduction

Restart or Alert On Nodes That stay NotReady for over 5 Minutes.

This was meant to reboot nodes in lab environments, but was modified to just send an email at one point.

This script uses kubectl to switch between contexts listed in lab_cluster.txt and records NotReady nodes.

If a node stays down for more then 5 minutes then a email is sent to the team members listed in the script.

An alert email has the following text.

Nodes in NotReady State
 

dev-cluster
172.27.120.44
172.27.120.4

cluster-lake-01
172.72.17.21

Installation

kubectl

install using kubectl site instructions.

You can find more information about configuring kubectl HERE

You will now need to use the secure copy command to transfer the file into your hosting VM

scp kubectl [email protected]:~

Now SSH into your box home directory and make the kubectl binary executable.

 chmod +x ./kubectl 

Move the binary in to your PATH.

 sudo mv ./kubectl /usr/local/bin/kubectl

now configure kubectl

You can find more information about configuring kubectl HERE

Install packages

  • sudo yum install python-pip
  • sudo pip install jinja2

Copy over kube_monitor.py script

Inside the repo on your local machine move app over to /usr/local/bin/app and add this to the remotes path

scp -r app [email protected]:/usr/local/bin/

Add to Path

echo 'export PATH=$PATH:/usr/local/bin/app' >> ~/.profile 

then

source ~/.profile

Set Timezone

ln -sf /usr/share/zoneinfo/America/Denver /etc/localtime

Setup The Script Cron Job

Edit the crontab by using the following command

crontab -e

The following top line starts the script at 9am Monday-Friday and the bottom goes and kills the script at 5pm Moday-Friday

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/app:~/.kube

0 9 * * 1-5 nohup /usr/bin/python /opt/app/kube_monitor.py  >> /tmp/kube_monitor.log 2>&1
0 17 * * 1-5 pkill -f kube_monitor.py

The lab_cluster.txt file

This file contains a cluster on each line and must be in the same folder as the kube_monitor script. These are the clusters you have setup for use with your kubectl.

Congrats, You did the thing.

kubernetes_restart_nodes_automation's People

Contributors

ispeakcomputer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.