我的專案中有 5 個任務需要定期運行。其中一些任務每天運行,一些每周運行。
我嘗試在 Docker 映像中容器化每個任務。這是一個說明性示例:
FROM tensorflow/tensorflow:2.7.0
RUN mkdir /home/MyProject
COPY . /home/MyProject
WORKDIR /home/MyProject/M1/src/
RUN pip install pandas numpy
CMD ./task1.sh
在上面定義的 task1.sh 檔案中有一個需要運行的 Python 腳本串列。這不是服務器應用什么的,它會運行task1.sh,它會一個一個運行其中定義的所有python腳本,整個程序將在幾分鐘內完成。同樣的程序應該在 24 小時后重復。
如何在 GCP 中安排此類 Docker 容器?有不同的方法嗎?如果有多種解決方案,哪一個更簡單?
無論如何,我都不是開發運維專家。我找到的檔案中的所有示例都是針對一直在運行的服務器應用程式進行的解釋,而不是像我的示例那樣,影像只需要定期運行一次。對于像我這樣的這個領域的初學者來說,這個話題是相當令人生畏的。
附錄:
在以下頁面上查看 Google 在 GKE 中的 cronjobs 檔案:https ://cloud.google.com/kubernetes-engine/docs/how-to/cronjobs
我找到以下 cronjob.yaml 檔案:
# cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
concurrencyPolicy: Allow
startingDeadlineSeconds: 100
suspend: false
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo "Hello, World!"
restartPolicy: OnFailure
據稱this cronjob prints the current time and a string once every minute。
但它是以一種假設您深刻理解頁面上發生的事情的方式記錄的,在這種情況下,您不需要閱讀檔案!
假設我有我希望它每天運行一次的影像,并且我的影像的名稱 - 比如說 - 是my_image。
我假設我應該為自己的影像更改以下部分。
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo "Hello, World!"
這些名稱和論點的含義完全是個謎。
name: hello
我想這只是用戶選擇的名稱,沒有任何實際意義。
image: busybox
這busybox是基礎圖嗎?如果不是,那是什么?它沒有說明這個busybox的東西是什么以及它來自哪里!
args:
- /bin/sh
- -c
- date; echo "Hello, World!"
根據頁面上的說明,這是將日期和"Hello, World!"字串列印到螢屏上的部分。
好的...那么,如何修改此模板以使用我自己的影像創建 cronjob my_image?該檔案根本沒有幫助!
uj5u.com熱心網友回復:
我同意@guillaume blaquiere。此外,Autopilot GKE 旨在降低管理集群的運營成本,優化集群以進行生產,并產生更高的作業負載可用性。操作模式是指您對集群的靈活性、責任和控制級別。除了完全托管的控制平面和節點自動化的優勢之外,GKE 還提供兩種操作模式:
- Autopilot:GKE 配置和管理集群的底層基礎設施,包括節點和節點池,為您提供優化的集群和無需干預的體驗。
- 標準:您管理集群的底層基礎架構,為您提供節點配置靈活性。
我希望泰語可以幫助您了解自動駕駛儀概述。
uj5u.com熱心網友回復:
我將在這里回答您的評論,因為您問題的第二部分太長而無法回答。
不要害怕,這是 Kubernetes API 定義的。您向控制平面宣告您想要的內容。它負責實作您的愿望!
# cronjob.yaml
apiVersion: batch/v1 # The API that you call
kind: CronJob # The type of object/endpoint in that API
metadata:
name: hello # The name of your job definition
spec:
schedule: "*/1 * * * *" # Your scheduling, change it to "0 10 * * *" to run your job every dat at 10.00am
concurrencyPolicy: Allow # config stuff, deep dive later
startingDeadlineSeconds: 100 # config stuff, deep dive later
suspend: false # config stuff, deep dive later
successfulJobsHistoryLimit: 3 # config stuff, deep dive later
failedJobsHistoryLimit: 1 # config stuff, deep dive later
jobTemplate: # Your execution definition
spec:
template:
spec:
containers:
- name: hello # Custom name of your container. Only to help you in case of debug, logs, ...
image: busybox # Image of your container, can be gcr.io/projectID/myContainer for example
args: # Args to pass to your container. You also have the "entrypoint" definition to change if you want. The entrypoint is the binary to run and that will receive the args
- /bin/sh
- -c
- date; echo "Hello, World!"
# You can also use "command" to run the command with the args directly. In fact it's WHAT you start in your container to perform the job.
restartPolicy: OnFailure # Config in case of failure.
您可以在此處了解有關 API 定義的更多詳細資訊
這里是容器的 API 定義,其中包含用于自定義它的所有可能值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/406970.html
標籤:
