Share via

how to restart only ingress pods through cron jobs

37821879 95 Reputation points
2024-01-22T09:21:37.8433333+00:00

How to restart only ingress pods via cron jobs

Azure Kubernetes Service
Azure Kubernetes Service

An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.

0 comments No comments

2 answers

Sort by: Most helpful
  1. AlaaBarqawi_MSFT 947 Reputation points Microsoft Employee
    2024-01-23T07:05:45.41+00:00

    Hi @37821879, to create cronjob to restart nginx deployment every day at midnight (00:00) using the schedule field. you can deploy this YAML If the answer has been helpful, we appreciate hearing from you and would love to help others who may have the same question. Accepting answers helps increase visibility of this question for other members of the Microsoft Q&A community. Thank you for helping to improve Microsoft Q&A! User's image

    apiVersion: batch/v1
    kind: CronJob
    metadata:
      name: restart-deployment
      namespace: nginx-basic
    spec:
      successfulJobsHistoryLimit: 1
      failedJobsHistoryLimit: 2
      concurrencyPolicy: Forbid
      schedule: "0 0 * * *"
      jobTemplate:
        spec:
          backoffLimit: 2 
          activeDeadlineSeconds: 600 
          template:
            spec:
              restartPolicy: Never
              containers:
                - name: kubectl
                  image: kubectl 
                  command:
                    - 'kubectl'
                    - 'rollout'
                    - 'restart'
                    - 'deployment/nginx'
    

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Anonymous
    2024-01-22T20:39:27.6433333+00:00

    @37821879
    I see you already have the answer for the command to run here. You simply can add a cron file or entry to crontab with the command that was provided.

    # restart at 1:00 am
    0 1 * * * root /path/to/kubectl --kubeconfig=/path/to/kubeconfig rollout restart deployment/<deployment-name> -n namespace
    
    

    Let me know if that answers your question or you need further assistance.


    If you still have questions, please let us know in the "comments" and we would be happy to help you. Comment is the fastest way of notifying the experts.

    If the answer has been helpful, we appreciate hearing from you and would love to help others who may have the same question. Accepting answers helps increase visibility of this question for other members of the Microsoft Q&A community.

    Thank you for helping to improve Microsoft Q&A! User's image

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.