我的專案中有 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/qiye/393146.html
標籤:码头工人 谷歌应用引擎 谷歌云平台 google-kubernetes-engine
