gpt4 book ai didi

cron - 从 Kubernetes Cron 作业调用端点

转载 作者:行者123 更新时间:2023-12-04 01:46:17 26 4
gpt4 key购买 nike

我有一个在 Kubernetes 集群的 Docker 容器中运行的 web 应用程序。该应用程序有一个我想定期调用的端点。该应用程序运行在多个节点/pod 上,并且只有一个节点执行端点发起的任务很重要。我查看了 Kubernetes Cron Jobs,但没有找到任何关于从 Kubernetes Cron Job 调用端点的文档。有没有人对解决这个问题有任何建议?在只有一个节点执行任务至关重要的集群中,您如何处理调度?

最佳答案

CronJob s 是不错的选择。这是一个运行 3 个接受所有流量的 nginx pod 的快速布局。每分钟,一个 Job curl 3 个 pod 中的 1 个(始终是同一个 pod )。

apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: main
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80

---

apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: singleton
labels:
app: nginx
special: singleton
spec:
replicas: 1
selector:
matchLabels:
app: nginx
special: singleton
template:
metadata:
labels:
app: nginx
special: singleton
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80

---

kind: Service
apiVersion: v1
metadata:
name: allpods
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80

---

kind: Service
apiVersion: v1
metadata:
name: singleton
spec:
selector:
special: singleton
ports:
- protocol: TCP
port: 80
targetPort: 80

---

apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: callout
spec:
schedule: "*/1 * * * *"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
containers:
- name: callout
image: buildpack-deps:curl
args:
- /bin/sh
- -ec
- curl http://singleton
restartPolicy: Never

关于cron - 从 Kubernetes Cron 作业调用端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47203080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com