Restart kubernetes workloads programmatically
kube-workload-restarter
is a small utility to be deployed in your Kubernetes namespace that is able to restart your workloads based on some conditions.
When we talk about workloads we are referring to the following resources:
Even if the idea behind
kube-workload-restarter
could be applied to all of these resources, currently only Deployment workloads are supported.
To install kube-workload-restarter
in your namespace you can use Helm:
helm repo add kube-workload-restarter https://andreacioni.github.io/kube-workload-restarter/
helm install kube-workload-restarter kube-workload-restarter/kube-workload-restarter --version <latest_version_here>
kube-workload-restarter
works by checking restart conditions by checking annotations on Deployments.
Currently supported annotations are:
restarter/after
: specify after how much time your workload will be restartedrestarter/when
: in addition to restarter/after
you can specify when a restart should happen. This annotation alone has no effect.You can set this annotaions on your own Deployment as shown below:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
annotations:
"restarter/after": "10d"
"restarter/when": "* 2-3 * * 3"
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
docker build -t andreacioni/kube-workload-restarter:latest .