简体   繁体   English

Kubernetes吊舱娱乐

[英]Kubernetes pod recreation

Is it possible to tell Kubernetes to just throw away my current pod and recreate it again every 48 hours? 是否可以告诉Kubernetes丢弃我当前的Pod,然后每48小时重新创建一次? Is there some type of a scheduler on Google Cloud Kubernetes? Google Cloud Kubernetes上是否有某种类型的调度程序? Or can I just configure my deployment this way? 还是可以这样配置我的部署? I have a Node.js application containerized with Docker running inside of a Kubernetes cluster on Google Cloud Platform. 我有一个与Docker一起容器化的Node.js应用程序,该应用程序在Google Cloud Platform的Kubernetes集群内部运行。 Thank you in advance! 先感谢您!

True "Kubernetes way" to resolve this issue - is to design ReadinessProbe / LivenessProbe for your app's deployment/statefulset/pod. 解决此问题的真正“ Kubernetes方式”是为应用程序的部署/状态集/容器设计ReadinessProbe / LivenessProbe Once your Pod fall down correct probes will handle it and your Pod will be recreated fully automatically 一旦您的Pod跌落,正确的探针将对其进行处理,并且您的Pod将被完全自动重建

PS: you are the one who knows your app better then anyone. PS:您是比其他人更了解您的应用的人。 Try out to resolve "every 48h issues" and then make the right probes. 尝试解决“每隔48小时的问题”,然后进行正确的调查。 Good luck! 祝好运!

Link: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/ 链接: https//kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/

Did you try CronJobs ? 您尝试过CronJobs吗?

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: your_app_name
            image: your_image
            args:
            - your
            - args
          restartPolicy: OnFailure

It's official Kubernetes docs under cron jobs . 它是cron job下的Kubernetes官方文档。

Also, here is a cron schedule expression editor that might be useful: crontab.guru . 另外,这是一个可能有用的cron计划表达式编辑器: crontab.guru

From what I understand, there are two ways to achieve this. 据我了解,有两种方法可以实现这一目标。 I'm assuming your app is running as a deployment in kubernetes, so deleting pod should create a new one. 我假设您的应用程序正在kubernetes中作为部署运行,因此删除pod应该创建一个新的。

  1. Exit your node app after 48 hours ie exit from within your code, a dirty way, but it's simplest. 48小时后退出节点应用程序,即从代码内退出,这是一种肮脏的方式,但这是最简单的。
  2. Create a cronjob that runs after 48 hours and delete any pod created under your deployment. 创建一个在48小时后运行的cronjob ,并删除在您的部署下创建的所有pod。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM