简体   繁体   English

从 K8S 集群运行 cron 作业

[英]Running cron job from K8S cluster

I need to run a third part API in schedulded interval from k8s cluster.我需要在 k8s 集群的预定时间间隔内运行第三方 API。 I have tried with k8s corn job but its not working getting error as invalid command .我曾尝试使用 k8s 玉米作业,但它不起作用,因为命令无效而出错。 I am using below script.我正在使用以下脚本。 Can anyone suggest how to use it任何人都可以建议如何使用它

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: corn-job
  namespace: scheduler
spec:
  schedule: "5 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            args:
            - /bin/sh
            - -c curl http://google.com
          restartPolicy: OnFailure

busybox image doesnt have curl binary. busybox 图像没有 curl 二进制文件。 it wont work.它不会工作。 use the below yaml or update the image使用下面的 yaml 或更新图像

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: cron-demo
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: ekambaram/curl
            command: ["curl"]
            args: ["http://google.com"]
          restartPolicy: OnFailure

just tested it and find below the output刚刚测试它并在输出下方找到

master $ kubectl get po
NAME                        READY   STATUS      RESTARTS   AGE
corn-job-1574850360-srwf6   0/1     Completed   0          44s

master $ kubectl logs -f corn-job-1574850360-srwf6
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
100   219  100   219    0     0     39      0  0:00:05  0:00:05 --:--:--    54

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

相关问题 将容器从Node / Angular UI部署到K8s集群 - Deploy containers from Node/Angular UI to K8s cluster k8s集群中从前端到后端的连接被拒绝 - connection refused from frontend to backend in k8s cluster 如何为在 K8s 集群之外的同一本地主机上运行的外部服务创建端点? - How do I create an Endpoint for an external service running on the same localhost outside of K8s cluster? 在K8s集群上运行的Docker容器内调用特定的Java主类 - Call specific java main class inside of docker container running on K8s cluster 如何将本地 k8s 集群上正在运行的应用程序公开给本地机器? - How do I expose running applications on local k8s cluster to my local machine? 使用没有 minikube 的 docker 文件的 k8s 集群中的部署问题,但我的 pod 没有运行 - Deployment issue in k8s cluster using docker file without minikube, but my is pod not running 从 docker 容器访问默认命名空间中具有集群 IP 的 k8s 服务 - Accessing a k8s service with cluster IP in default namespace from a docker container 在 K8S 集群中切换容器运行时。 从 CRI-O 到 docker - Switch container runtime in K8S cluster. From CRI-O to docker 在K8s中,我无法使用选择器应用程序中的群集IP远程登录到端口 - In K8s I can not telnet to the port using the cluster IP from selector app 在现有k8s集群上预取docker映像 - pre-fetch docker image on existing k8s cluster
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM