Skip to content

Instantly share code, notes, and snippets.

@Voronenko
Created February 23, 2021 08:03
Show Gist options
  • Save Voronenko/c034290e4491df2f9564350a3bddbfa6 to your computer and use it in GitHub Desktop.
Save Voronenko/c034290e4491df2f9564350a3bddbfa6 to your computer and use it in GitHub Desktop.
Nightly rollout on schedule
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: specific-deployment-restart
namespace: <YOUR NAMESPACE>
spec:
concurrencyPolicy: Forbid
schedule: '0 8 * * *' # cron spec of time, here, 8 o'clock
jobTemplate:
spec:
backoffLimit: 2 # this has very low chance of failing, as all this does
# is prompt kubernetes to schedule new replica set for
# the deployment
activeDeadlineSeconds: 600
template:
spec:
serviceAccountName: specific-deployment-restart
restartPolicy: Never
containers:
- name: kubectl
image: voronenko/cdci-helm-kubectl
# any other with kubectl is ok
# above one is for https://github.com/Voronenko/cdci-helm-kubectl
command:
- 'kubectl'
- 'rollout'
- 'restart'
- 'deployment/<YOUR DEPLOYMENT NAME>'
---
# Service account the client will use to reset the deployment,
# by default the pods running inside the cluster can do no such things.
kind: ServiceAccount
apiVersion: v1
metadata:
name: specific-deployment-restart
namespace: <YOUR NAMESPACE>
---
# allow getting status and patching only the one deployment you want
# to restart
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: specific-deployment-restart
namespace: <YOUR NAMESPACE>
rules:
- apiGroups: ["apps", "extensions"]
resources: ["deployments"]
resourceNames: ["<YOUR DEPLOYMENT NAME>"]
verbs: ["get", "patch", "list", "watch"] # "list" and "watch" are only needed
# if you want to use `rollout status`
---
# bind the role to the service account
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: specific-deployment-restart
namespace: <YOUR NAMESPACE>
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: specific-deployment-restart
subjects:
- kind: ServiceAccount
name: specific-deployment-restart
namespace: <YOUR NAMESPACE>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment