首页 > 其他分享 >定时重启pod

定时重启pod

时间:2023-08-20 22:11:05浏览次数:60  
标签:kubectl kind name 重启 spec deployment pod 定时 restart

https://juejin.cn/s/k8s定时重启pod

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: my-cronjob
spec:
  schedule: "0 1 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: my-container
            image: my-image
          restartPolicy: OnFailure
        metadata:
          name: my-pod

2.使用cronjob命令配合rollout restart每天定时重启动pod

https://www.xiaowu95.wang/posts/26c255e0/

#Service account the client will use to reset the deployment,
#by default the pods running inside the cluster can do no such things.
kind: ServiceAccount
apiVersion: v1
metadata:
  name: deployment-restart
  namespace: <YOUR NAMESPACE>
---
# allow getting status and patching only the one deployment you want
# to restart
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: deployment-restart
  namespace: <YOUR NAMESPACE>
rules:
  - apiGroups: ["apps", "extensions"]
    resources: ["deployments"]
    resourceNames: ["<YOUR DEPLOYMENT NAME>"]
    verbs: ["get", "patch", "list", "watch"] # "list" and "watch" are only needed
                                             # if you want to use `rollout status`
---
# bind the role to the service account
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: deployment-restart
  namespace: <YOUR NAMESPACE>
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: deployment-restart
subjects:
  - kind: ServiceAccount
    name: deployment-restart
    namespace: <YOUR NAMESPACE>
---
# cronjob配置:
apiVersion: batch/v1
kind: CronJob
metadata:
  name: deployment-restart
  namespace: <YOUR NAMESPACE>
spec:
  concurrencyPolicy: Forbid
  schedule: '0 8 * * *' # cron spec of time, here, 8 o'clock
  jobTemplate:
    spec:
      backoffLimit: 2 # this has very low chance of failing, as all this does
                      # is prompt kubernetes to schedule new replica set for
                      # the deployment
      activeDeadlineSeconds: 600 # timeout, makes most sense with 
                                 # "waiting for rollout" variant specified below
      template:
        spec:
          serviceAccountName: deployment-restart # name of the service
                                                 # account configured above
          restartPolicy: Never
          containers:
            - name: kubectl
              image: bitnami/kubectl # probably any kubectl image will do,
                                     # optionaly specify version, but this
                                     # should not be necessary, as long the
                                     # version of kubectl is new enough to
                                     # have `rollout restart`
              command:
                - 'kubectl'
                - 'rollout'
                - 'restart'
                - 'deployment/<YOUR DEPLOYMENT NAME>'

如果希望cronjob等待部署完成,可以将cronjob命令更改为:

command:
 - bash
 - -c
 - >-
   kubectl rollout restart deployment/<YOUR DEPLOYMENT NAME> &&
   kubectl rollout status deployment/<YOUR DEPLOYMENT NAME>

标签:kubectl,kind,name,重启,spec,deployment,pod,定时,restart
From: https://www.cnblogs.com/regit/p/17644722.html

相关文章

  • 【工具】windows10定时关机
    windows10定时关机打开 cmd (在搜索栏输入cmd打开):2.2、创建计划任务:schtasks/create/TNshutdown_on_time/TR"shutdown/s/t60"/ST22:00:00/SCDAILY自己用的话只需改一个地方,把22:00:00改成自己需要的时间就行了3、查看创建结果:schtasks/Delete/TNshu......
  • CH32V003的系统定时器SysTick
    在CH32V003内部有一个特殊的定时器——系统定时器(SysTick),它位于青稞V2微处理内核里面,是RISC-V内核的一个组成部分,主要用来给操作系统提供时间片轮转的定时,一般固定为10ms的定时,所以中文也称它为“嘀嗒”定时器(也称“心跳”定时器)。在不跑操作系统时,可以把它当作普通定时器来使用,一......
  • Linux之定时器
    Linux下的实现方式socket选项SO_RECVTIMEO和SO_SNDTIMEOSIGALRM信号信号相关笔记:Linux之信号I/O复用系统调用的超时参数定时器及其容器定时器封装了以下内容超时时间回调函数:就是每次时间到了要干嘛连接资源:包括客户端socket地址、socket文件描述符、定......
  • 高级定时器寄存器
    TIMx_CR1TIM1&TIM8controlregister1TIM1和TIM8控制寄存器1TIMx_CR2TIM1&TIM8controlregister2TIM1和TIM8控制寄存器2TIMx_SMCRTIM1&TIM8slavemodecontrolregisterTIM1和TIM8从模式控制寄存器TIMx_DIERTIM1&TIM8DMA/interruptenablereg......
  • 高级定时器 捕获比较通道
    捕获比较输入阶段TIMx_CH1通道输入阶段详细 输入阶段滤波器采样频率  CKD[1:0]滤波器边沿检测器,检测上升沿和下降沿TI1F_ED双边沿信号选择上升沿或下降沿来自CH2的信号信号选择分频通道使能信号进入主电路捕......
  • Python3 - 时间处理与定时任务
    无论哪种编程语言,时间肯定都是非常重要的部分,今天来看一下python如何来处理时间和python定时任务,注意咯:本篇所讲是python3版本的实现,在python2版本中的实现略有不同,有时间会再写一篇以便大家区分。1.计算明天和昨天的日期12345678910111213#!/usr/bin/envpython#coding=utf-8#获......
  • Advanced-control timer 高级定时器 时钟源
    Advanced-controltimer TIM1TIM8TIM8isnotavailableinSTM32F411xC/E.Clockselection时钟选择Internalclock(CK_INT)内部时钟(CK_INT),来自APB总线Externalclockmode1:externalinputpin外部时钟模式1:外部输入引脚来自CH1,CH2ED:双边沿检测(e......
  • 定时器之PWM
      voidPWM_Init(void){RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);GPIO_PinRemapConfig(GPIO_PartialRemap1_TIM2,......
  • 如何设计一个定时任务?
    一.日常工作中使用到的框架?单机:Quartz,SpringSchedule等框架;分布式:SchedulerX,ElasticJob,xxlJob等分布式任务调度二.定时任务的作用简单来讲为某个时间执行某些具体的任务1.数据获取 2.财务账目核对3.定时数据备份4.定时更新数据平台的数据三.定时任务可以使用什么数......
  • windows程序如何设置开机自启动以及定时重启
    1. 通过shell:StartUp将程序设置为开机自启动的状态  2. 设置windows系统为无需登录模式 1、开始-运行,或点击Cortana搜索框,输入netplwiz,打开用户账户面板;2、点击当前使用的用户名,去掉“要使用本计算机,用户必须输入用户名和密码”复选框;没有以上复选项的解决方法 ......