Skip to content

Instantly share code, notes, and snippets.

@magickatt
Last active April 15, 2024 20:39
Show Gist options
  • Save magickatt/e2778142d832e39f07ed18c13f4e46b5 to your computer and use it in GitHub Desktop.
Save magickatt/e2778142d832e39f07ed18c13f4e46b5 to your computer and use it in GitHub Desktop.

Revisions

  1. magickatt revised this gist Apr 15, 2024. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions scheduled_deployment_restart.yaml
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    apiVersion: batch/v1
    kind: CronJob
    metadata:
    name: "restart-{{ $service.name }}"
    name: "restart-{{ $application.name }}"
    namespace: "{{ $.Release.Namespace }}"
    spec:
    concurrencyPolicy: Forbid
    @@ -20,10 +20,10 @@ spec:
    command:
    - 'kubectl'
    - '--namespace'
    - '{{ $job.namespace }}'
    - '{{ $application.namespace }}'
    - 'rollout'
    - 'restart'
    - 'deployment/{{ $service.name }}'
    - 'deployment/{{ $application.name }}'
    ---
    kind: ServiceAccount
    apiVersion: v1
    @@ -44,7 +44,7 @@ apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
    name: pod-restarter
    namespace: {{ $service.namespace }}
    namespace: {{ $application.namespace }}
    roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: ClusterRole
  2. magickatt created this gist Apr 15, 2024.
    55 changes: 55 additions & 0 deletions scheduled_deployment_restart.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    apiVersion: batch/v1
    kind: CronJob
    metadata:
    name: "restart-{{ $service.name }}"
    namespace: "{{ $.Release.Namespace }}"
    spec:
    concurrencyPolicy: Forbid
    schedule: "* * * * *" # crontab.guru
    jobTemplate:
    spec:
    backoffLimit: 3
    activeDeadlineSeconds: 600
    template:
    spec:
    serviceAccountName: pod-restarter
    restartPolicy: Never
    containers:
    - name: kubectl
    image: bitnami/kubectl:1.28 # bitnami.com/stack/kubectl/containers
    command:
    - 'kubectl'
    - '--namespace'
    - '{{ $job.namespace }}'
    - 'rollout'
    - 'restart'
    - 'deployment/{{ $service.name }}'
    ---
    kind: ServiceAccount
    apiVersion: v1
    metadata:
    name: pod-restarter
    namespace: {{ .Release.Namespace }}
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
    name: pod-restarter
    rules:
    - apiGroups: ["apps", "extensions"]
    resources: ["deployments"]
    verbs: ["get", "patch", "list", "watch"]
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
    name: pod-restarter
    namespace: {{ $service.namespace }}
    roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: ClusterRole
    name: pod-restarter
    subjects:
    - kind: ServiceAccount
    name: pod-restarter
    namespace: {{ $.Release.Namespace }}