Scheduled Deployment Pod rollout restarts using Kubernetes CronJob

Most of the time your Deployments will self-heal when your Pods crash, Nodes go down or other unexpected circumstances. When your Pods get stuck, projects like https://github.com/kubernetes-sigs/descheduler do a good job of automatically restarting or rescheduling them. But what if you just want a simple restart every so often (say once a week) or on specific days of the month? Then all you need is a CronJob.

Have included placeholders where the Helm release namespace would represent where these resources are created and managed, versus the namespace of the application(s) you are trying to restart. If you template this with Helm values you can avoid using a ClusterRoleBinding to allow the ServiceAccount to restart Deployments anywhere in the cluster, but only the namespaces of the applications you are restarting.

Many thanks to https://stackoverflow.com/questions/52422300/how-to-schedule-pods-restart/58378834#58378834 for the clear and concise examples!

Add comment