使用 Kubeflow Pipelines SDK 连接到 AI Platform Pipelines

您可以使用 Kubeflow Pipelines SDK 管理和自动化 AI Platform Pipelines 集群上的活动,例如:

  • 将流水线加载到您的 AI Platform Pipelines 集群中
  • 运行流水线
  • 检索有关流水线和运行的信息

本指南将介绍如何使用 Kubeflow Pipelines SDK 连接到您的 AI Platform Pipelines 集群。

前期准备

使用 Kubeflow Pipelines SDK 连接到集群之前,必须先设置 AI Platform Pipelines 集群,安装 Kubeflow Pipelines SDK,并确保您有足够的权限来访问 AI Platform Pipelines 集群。

  1. 按照指南设置您的 AI Platform Pipelines 集群

  2. 安装或更新 Kubeflow Pipelines SDK0.5.21.0.4 或更高版本。

  3. 如要使用 Kubeflow Pipelines SDK 访问 AI Platform Pipelines 集群,您必须拥有 Google Kubernetes Engine 集群服务账号的 Service Account User 角色。

    详细了解如何授予用户对 AI Platform Pipelines 的访问权限

使用 Kubeflow Pipelines SDK 连接到 AI Platform Pipelines 集群

请按照以下说明,使用 Kubeflow Pipelines SDK 连接到您的 AI Platform Pipelines 集群。

  1. 在 Google Cloud 控制台中打开 AI Platform Pipelines。

    打开 AI Platform Pipelines

  2. 如需查看您的 Kubeflow Pipelines 集群情况,请点击打开流水线信息中心。Kubeflow Pipelines 界面将在新标签页中打开。

  3. 在 Kubeflow Pipelines 信息中心的网址中找到主机名和网址架构。主机名和架构是网址中介于开头与 /#/start 之间的部分。主机名和架构应该与格式 https://*.pipelines.googleusercontent.com 相匹配。

  4. 使用 Kubeflow Pipelines SDK 从 Jupyter 笔记本或 Python 客户端连接到您的 AI Platform Pipelines 集群。

    import kfp
    client = kfp.Client(host='https://example.com')
    

    https://example.com 替换为您的集群的主机名和架构。

  5. 现在,您可以使用 Kubeflow Pipelines SDK 与您的集群进行互动了。例如,以下命令会列出集群的流水线。

    client.list_pipelines()
    

后续步骤