简体   繁体   English

如何在 kube.netes 集群中的单个 pod 上运行 quartz 任务?

[英]How to run quartz task on single pod in kubernetes cluster?

I've a Spring MVC project in which quartz tasks are currently bound to virtual machines in mysql table and based on these mapping, we execute the task on that respective server.我有一个 Spring MVC 项目,其中石英任务当前绑定到 mysql 表中的虚拟机,并且基于这些映射,我们在相应的服务器上执行任务。

Eg:例如:
Task1: admin-3002任务 1:admin-3002
Task2: admin-4001任务 2:admin-4001

Now we've moved this application into the kube.netes cluster but since hostnames are not static in kube.netes, every task is executed on all available pods.现在我们已将此应用程序移至 kube.netes 集群中,但由于 kube.netes 中的主机名不是 static,因此每个任务都在所有可用的 pod 上执行。

Can anyone suggest an optimal solution to this problem.任何人都可以建议这个问题的最佳解决方案。 Would consistent hashing be a good solution to achieve this?一致性哈希是实现这一目标的好解决方案吗?

We're currently running a single pod to avoid tasks running on all pods but need to find a better way to resolve this issue.我们目前正在运行单个 pod 以避免在所有 pod 上运行任务,但需要找到更好的方法来解决此问题。

The easiest way is to create a lock table in your MySQL database with the jobname as unique identifier.最简单的方法是在 MySQL 数据库中创建一个锁表,并将作业名称作为唯一标识符。

When a job start try to write a record to that table.当作业开始时,尝试向该表写入一条记录。

When there is already a record for your job just stop processing your job.当你的工作已经有记录时,就停止处理你的工作。

When there is no lock create and commit the lock, process the job and at the end remove the lock.当没有锁创建并提交锁时,处理作业并在最后删除锁。

A nice solution to this would be leader election, potentially using kube api. Less clean but potentially as successfull would be to use StatefulSet and execute certain logic only on the pod with a -0 suffix as sts pods are numbered sequentially, always from 0一个很好的解决方案是领导者选举,可能使用 kube api。不太干净但可能同样成功的是使用 StatefulSet 并仅在带有-0后缀的 pod 上执行某些逻辑,因为 sts pod 按顺序编号,始终从 0

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

相关问题 如果 Kubernetes 上存在多个 pod,则从单个 pod 运行 Spring 中的计划 Cron 方法 - Run Scheduled Cron method in Spring from single pod if multiple pods exist on Kubernetes 如何从石英集群中删除一个集群 - How to remove one cluster from quartz cluster 在Quartz JDBC支持的集群的每个节点上运行作业 - Run a job on every node of a Quartz JDBC backed cluster 无法让Quartz任务在Spring Web MVC中运行 - Unable to get Quartz task to run in Spring web mvc 如何使用默认 spring.datasource 启动石英集群? - How to start a quartz cluster using default spring.datasource? Spring 启动微服务正在以 pod 名称作为 Kubernetes 集群中的主机名注册到 Eureka - docker 桌面 - Spring boot microservices are getting registered to Eureka with the pod name as the hostname in the Kubernetes cluster - docker desktop 如何配置 JBoss/Quartz 以运行 Spring 作业? - How to configure JBoss/Quartz to run Spring job? 如何覆盖 kubernetes 集群中的配置环境? - How to override configure the environment in kubernetes cluster? 如何在每个 pod 中获取所有 Kube.netes pod IP? - How to get all Kubernetes pod IP in each pods? 集群中的弹簧集成+ cron + quartz? - spring integration + cron + quartz in cluster?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM