在Kubernetes中的Pod中运行Cronjob

编程入门 行业动态 更新时间:2024-10-23 12:24:55
本文介绍了在Kubernetes中的Pod中运行Cronjob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个在kubernetes集群中运行的后端nodeJS应用程序.现在,我想每月运行两个计划的cron作业. cron作业位于JS文件中.我如何使用Kubernetes创建一个工作来每月在运行该服务的Pod中运行那些JS文件? 此链接提供了有关其工作原理的基本理解,但我对如何针对特定服务和特定pod运行它感到有些困惑. "> kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#编写一份cron-job-spec

I have a backend nodeJS application running in a kubernetes cluster. Now I want to run two cron jobs to be scheduled every month. The cron jobs are in a JS file. How do I create a job that runs those JS files in the pod running that service every month using Kubernetes ? This link gives a basic understanding of how it works but I am a little confused on how to run it for a specific service and on a specific podkubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#writing-a-cron-job-spec

推荐答案

不幸的是,您无法运行应用程序容器中的CronJob .

Unfortunately, you cannot run the CronJob inside a container of your application.

您唯一可以做的就是创建一个容器,其中将包含您的cronjob和运行它的必要环境,并安排CronJob运行该pod.

The only thing you can do is create a container which will contain your cronjob and necessary environment for running it and schedule to run that pod by a CronJob.

以下是配置示例:

apiVersion: batch/v1beta1 kind: CronJob metadata: name: hello spec: schedule: "*/1 * * * *" # syntax is a same as in system cron jobs jobTemplate: spec: template: spec: containers: - name: hello image: image_with_cronjob_code # here is an image with your cronjob args: - /bin/sh - -c - date; echo Hello from the Kubernetes cluster restartPolicy: OnFailure

更多推荐

在Kubernetes中的Pod中运行Cronjob

本文发布于:2023-07-16 04:13:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117720.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Kubernetes   Pod   Cronjob

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!