我想使用 CronJob 在 Kubernetes 中运行一个 shell 脚本,这是我的 CronJon.yaml 文件:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- /home/admin_/test.sh
restartPolicy: OnFailure
CronJob 已创建(kubectl apply -f CronJob.yaml) 当我获得 cronjob 列表时,我可以看到 cron 作业 ( kubectl get cj ),当我运行“kubectl get pods”时,我可以看到正在创建 pod,但 pod 崩溃了。 谁能帮助我学习如何在 Kubernetes 中创建 CronJob?
最佳答案
正如评论中正确指出的那样,您需要提供脚本文件才能通过您的 CronJob
执行它。您可以通过将文件安装在 volume 中来做到这一点.例如,您的 CronJob
可能如下所示:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- /myscript/test.sh
volumeMounts:
- name: script-dir
mountPath: /myscript
restartPolicy: OnFailure
volumes:
- name: script-dir
hostPath:
path: /path/to/my/script/dir
type: Directory
上面的例子展示了如何使用 hostPath卷的类型,以便安装脚本文件。
https://stackoverflow.com/questions/68014653/
相关文章:
flutter - 检查 flutter 中的连接并根据连接状态更改状态
react-native - SectionList React Native 上的粘性 heade
c++ - 无法将 'v8::MaybeLocal
flutter - 如何将二进制字符串转换为文本字符串并在 flutter 中反转?
python - Django Channels - Websocket 连接失败
javascript - Next JS 和 Cloudinary,图像未加载