Created
September 7, 2023 14:13
-
-
Save yunusemrecatalcam/4a7fcbac4669823740223cc4f5fbf147 to your computer and use it in GitHub Desktop.
stack to restart a deployment on kubernetes periodically - cronjob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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