<p>I want to periodically restart the deployment using k8s cronjob.</p>
<p>Please check what is the problem with the yaml file.</p>
<p>When I execute the command from the local command line, the deployment restarts normally, but it seems that the restart is not possible with cronjob.
e.g $ kubectl rollout restart deployment my-ingress -n my-app</p>
<h2>my cronjob yaml file</h2>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: deployment-restart
  namespace: my-app
spec:
  schedule: '0 8 */60 * *' 
  jobTemplate:
    spec:
      backoffLimit: 2 
      activeDeadlineSeconds: 600 
      template:
        spec:
          serviceAccountName: deployment-restart 
          restartPolicy: Never
          containers:
            - name: kubectl
              image: bitnami/kubectl:latest 
              command:
                - 'kubectl'
                - 'rollout'
                - 'restart'
                - 'deployment/my-ingress -n my-app'
</code></pre>

<p>as David suggested run cron of <strong>kubectl</strong> is like by executing the command</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: &quot;*/5 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: sa-jp-runner
          containers:
          - name: hello
            image: bitnami/kubectl:latest
            command:
            - /bin/sh
            - -c
            - kubectl rollout restart deployment my-ingress -n my-app
          restartPolicy: OnFailure
</code></pre>
<p>i would also suggest you to check the <strong>role</strong> and <strong>service account</strong> permissions</p>
<p>example for ref :</p>
<pre><code>kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: default
  name: kubectl-cron
rules:
- apiGroups:
  - extensions
  - apps
  resources:
  - deployments
  verbs:
  - 'patch'

---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: kubectl-cron
  namespace: default
subjects:
- kind: ServiceAccount
  name: sa-kubectl-cron
  namespace: default
roleRef:
  kind: Role
  name: kubectl-cron
  apiGroup: &quot;&quot;

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: sa-kubectl-cron
  namespace: default

---
</code></pre>
