Skip to content

Commit

Permalink
add node restart sleep delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg May committed Feb 16, 2020
1 parent b0d9516 commit 1952fd7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# kubectl-node-restart

`kubectl-node-restart` is a [kubectl plugin](https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/) that sequentially and gracefully performs a rolling restart of nodes within a Kubernetes cluster
`kubectl-node-restart` is a [kubectl plugin](https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/) that sequentially and gracefully performs a rolling restart of Nodes within a Kubernetes cluster

![using kubectl-node-restart plugin](demo/usage.gif)

Expand All @@ -23,7 +23,7 @@
- restart only specific nodes selected through labels

```bash
kubectl node-restart --selector=kubernetes.io/master
kubectl node-restart --selector node-role.kubernetes.io/master
```

- perform a dry-run
Expand All @@ -37,3 +37,9 @@
```bash
kubectl node-restart all --force
```

- add a delay of 120seconds between node restarts

```bash
kubectl node-restart all --sleep 120
```
Binary file added demo/usage.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions node-restart.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

image='alpine:3.9'
nodesleep=10 #Time between node restarts - give pods time to start up
nodesleep=20 #Time delay between node restarts - give pods time to start up
force=false
dryrun=false
blue='\033[0;34m'
nocolor='\033[0m'

function print_usage() {
echo "Usage: $0 [<options>]"
echo "Usage: kubectl node-restart [<options>]"
echo ""
echo "all Restarts all nodes within the cluster"
echo ""
Expand All @@ -18,6 +18,8 @@ function print_usage() {
echo ""
echo "-d|--dry-run Just print what to do; don't actually do it"
echo ""
echo "-s|--sleep Sleep delay between restarting Nodes (default 20s)"
echo ""
echo "-h|--help Print usage and exit"
}

Expand All @@ -43,6 +45,11 @@ do
dryrun=true
shift
;;
-s|--sleep)
nodesleep="$2"
shift
shift
;;
-h|--help)
print_usage
exit 0
Expand Down
33 changes: 14 additions & 19 deletions node-restart.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: node-restart # plugin name must match your manifest file name (e.g. foo.yaml)
name: node-restart
spec:
version: "v0.0.1" # required, must be in semver format, prefixed with "v"
version: "v0.0.2"
platforms:
# specify installation script for linux and darwin (macOS)
- selector: # a regular Kubernetes selector
- selector:
matchExpressions:
- {key: os, operator: In, values: [darwin, linux]}
# url for downloading the package archive:
uri: https://github.com/mnrgreg/kubectl-node-restart/releases/v0.0.1.zip
# sha256sum of the above archive file:
sha256: "db32ebd8b6caf574036a12f97ee281905daf8da25ff6e4554edf71d7af473148"
# copy the used files out of the zip archive, defaults to `[{from: "*", to: "."}]`
uri: https://github.com/MnrGreg/kubectl-node-restart/releases/download/v0.0.2/v0.0.2.zip
sha256: "44db0eee9603085652837d26c5352287864f158b557f78ae19325724640535f8"
files:
- from: "*.sh" # path to the files extracted from archive
to: "." # '.' refers to the root of plugin install directory
- from: "LICENSE" # always install your LICENSE file
- from: "*.sh"
to: "."
- from: "LICENSE"
to: "."
bin: "kubectl-node-restart" # path to the plugin executable after copying files above
shortDescription: >- # short description gets truncated at ~50 chars
Restarts K8S nodes sequentially & gracefully
bin: "node-restart.sh"
shortDescription: >-
Restart Kubernetes Nodes sequentially & gracefully
homepage: https://github.com/mnrgreg/kubectl-node-restart
# (optional) use caveats field to show post-installation recommendations
caveats: |
This plugin requires execution with cluster-admin priveleges.
Execution of this plugin requires Kubernetes cluster-admin Rolebindings.
description: |
This plugin performs a sequential, rolling restart of selected nodes by first
draining each node, then running a kubernetes job to reboot each host, and
finally uncordoning each node when Ready.
Draining each node, then running a Kubernetes Job to reboot each node, and
finally Uncordoning each node when Ready.

0 comments on commit 1952fd7

Please sign in to comment.