Skip to content

Instantly share code, notes, and snippets.

@yunusemrecatalcam
Created September 7, 2023 14:13
Show Gist options
  • Save yunusemrecatalcam/4a7fcbac4669823740223cc4f5fbf147 to your computer and use it in GitHub Desktop.
Save yunusemrecatalcam/4a7fcbac4669823740223cc4f5fbf147 to your computer and use it in GitHub Desktop.
stack to restart a deployment on kubernetes periodically - cronjob
apiVersion: v1
kind: ServiceAccount
metadata:
name: restart-deployment-sa
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: prod
name: deployment-restarter
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "update", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: deployment-restarter-binding
namespace: prod
subjects:
- kind: ServiceAccount
name: restart-deployment-sa
namespace: prod
roleRef:
kind: Role
name: deployment-restarter
apiGroup: rbac.authorization.k8s.io
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: deployment-restart-cronjob
spec:
schedule: "*/30 * * * *"
jobTemplate:
spec:
template:
spec:
serviceAccountName: restart-deployment-sa
containers:
- name: restart-deployment
image: <use an image that has kubectl installed>
command: ["kubectl"]
args:
- "rollout"
- "restart"
- "deployment/daory-monstache"
restartPolicy: OnFailure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment