How to schedule pods restart

前端 未结 6 1059

Is it possible to restart pods automatically based on the time?

For example, I would like to restart the pods of my cluster every morning at 8.00 AM.

6条回答
  •  甜味超标
    2020-12-05 19:38

    Another quick and dirty option for a pod that has a restart policy of Always (which cron jobs are not supposed to handle - see creating a cron job spec pod template) is a livenessProbe that simply tests the time and restarts the pod on a specified schedule

    ex. After startup, wait an hour, then check hour every minute, if hour is 3(AM) fail probe and restart, otherwise pass

    livenessProbe:
      exec:
        command:
        - exit $(test $(date +%H) -eq 3 && echo 1 || echo 0)
      failureThreshold: 1
      initialDelaySeconds: 3600
      periodSeconds: 60
    

    Time granularity is up to how you return the date and test ;)

    Of course this does not work if you are already utilizing the liveness probe as an actual liveness probe ¯\_(ツ)_/¯

提交回复
热议问题