Kubernetes中的Cronjob可以重新启动(删除)部署中的Pod [英] Cronjob in Kubernetes to restart (delete) the pod in a deployment

查看:1163
本文介绍了Kubernetes中的Cronjob可以重新启动(删除)部署中的Pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Kubernetes运行Docker服务.这是一项有缺陷的服务,需要每天重新启动.由于多种原因,我们无法以编程方式解决该问题,仅每天重启docker即可. 当我迁移到Kubernetes时,我注意到我无法执行"docker restart [mydocker]",但是由于docker是具有reCreate策略的部署,因此我只需要删除pod即可让Kubernetes创建一个新的容器.

I am using Kubernetes to run a Docker service. This is a defective service that requires a restart everyday. For multiple reasons we can't programmatically solve the problem and just restarting the docker everyday will do. When I migrated to Kubernetes I noticed I can't do "docker restart [mydocker]" but as the docker is a deployment with reCreate strategy I just need to delete the pod to have Kubernetes create a new one.

我可以使用Kubernetes中的CronTask自动执行删除Pod的任务,或者另一种方法来重新启动它吗?

Can I automate this task of deleting the Pod, or an alternative one to restart it, using a CronTask in Kubernetes?

感谢任何指导/示例.

我当前的部署yml:

apiVersion: v1
kind: Service
metadata:
  name: et-rest
  labels:
    app: et-rest
spec:
  ports:
    - port: 9080
      targetPort: 9080
      nodePort: 30181
  selector:
    app: et-rest
    tier: frontend
  type: NodePort
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: et-rest
  labels:
    app: et-rest
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: et-rest
        tier: frontend
    spec:
      containers:
      - image: et-rest-image:1.0.21
        name: et-rest
        ports:
        - containerPort: 9080
          name: et-rest
        volumeMounts:
        - name: tz-config
          mountPath: /etc/localtime
      volumes:
      - name: tz-config
        hostPath:
          path: /usr/share/zoneinfo/Europe/Madrid

推荐答案

您可以使用预定的作业窗格:

You can use a scheduled job pod:

预定的作业窗格具有内置的cron行为,可以结合超时行为重新启动作业,从而导致您所需的行为或每隔X个小时重新启动应用程序.

A scheduled job pod has build in cron behavior making it possible to restart jobs, combined with the time-out behavior, it leads to your required behavior or restarting your app every X hours.

apiVersion: batch/v2alpha1
kind: ScheduledJob
metadata:
  name: app-with-timeout
spec:
  schedule: 0 * * * ?
  jobTemplate:
    spec:
      activeDeadlineSeconds: 3600*24
      template:
        spec:
          containers:
          - name: yourapp
            image: yourimage

这篇关于Kubernetes中的Cronjob可以重新启动(删除)部署中的Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆