![](/img/trans.png)
[英]how to update the credentials for Azure Kubernetes Service (AKS)
[英]How to deploy a Kubernetes Job at AKS with Prefect
我是 Prefect 的新手,想使用 Prefect 在 Azure Kube.netes 服務部署 Kube.netes 作業。 我已經設置了一個 Linux 容器,包括 Prefect、kubectl。 我可以建立到 AKS 集群的連接,並且通過使用 kubectl,我可以在 AKS 上部署一個 Kube.netes 作業。 但是它如何與 Prefect 一起使用呢? 在容器中,我存儲了 .py 文件和一個 YAML 文件,它定義了 Kube.netes 作業。
--> kubectl apply -f deploytestcontainer.yaml --> 有效
運行附加示例 Prefect 代碼也有效(但作業未在 AKS 上部署)
這就是“firstk8sjob.py”的內容
import prefect
from prefect import task, Flow
from prefect.run_configs import KubernetesRun
@task
def hello_task():
flow.run_config = KubernetesRun(job_template_path="deploytestcontainer.yaml")
logger = prefect.context.get("logger")
logger.info("Hello world!")
with Flow("hello-flow") as flow:
hello_task()
flow.run()
非常感謝您的建議!
將流部署到 Azure AKS 有兩個步驟:
首先,您需要部署一個 Kube.netes 代理。 您可以使用以下方法生成清單文件:
prefect agent kubernetes install --rbac --key YOUR_API_KEY --label YOUR_LABEL > agent.yaml
然后你可以檢查文件,並根據需要修改它(例如更改圖像版本以匹配你想要的 Python 和 Prefect 版本,在需要時添加環境變量等)。
請注意,API 密鑰用於 Prefect Cloud - 您是 Prefect Cloud 還是 Prefect Server 用戶? 如果你在 Prefect Server 上,你還需要那些環境變量。
清單准備就緒后,您可以將其應用於 AKS 群集:
kubectl apply -f agent.yaml # optionally set: -n yournamespace
然后,代理運行后,您只需在 Kube.netesRun 上指定Kube.netesRun
即可部署流程。
請注意,您在不推薦的任務中設置運行配置,這可能是導致問題的原因。 您應該將運行配置附加到流 object,如下所示:
import prefect
from prefect import task, Flow
from prefect.run_configs import KubernetesRun
@task
def hello_task():
logger = prefect.context.get("logger")
logger.info("Hello world!")
with Flow("hello-flow", run_config=KubernetesRun(labels=["YOUR_LABEL"])) as flow:
hello_task()
if __name__ == "__main__":
flow.register("YOUR_PROJECT_NAME")
您還可以在您的 CLI 中注冊並擺脫這個"__main__"
塊:
prefect register --project YOUR_PROJECT_NAME -p path/to/flow.py
注冊流后,您可以使用以下命令在 AKS 上觸發運行:
prefect run --name "hello-flow" --project YOUR_PROJECT_NAME --watch
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.