[英]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.