创建 Data Science Pipelines Application

本指南介绍如何创建一个 DataSciencePipelinesApplication(DSPA)——即命名空间中的一个隔离的 Kubeflow Pipelines v2 栈——然后使用 kfp Python SDK 进行访问。

你可以通过两种方式创建 DSPA:

  • kubectl —— 应用 DataSciencePipelinesApplication 清单。
  • Alauda Console UI —— 依次进入 AdministratorMarketplaceOperatorHubData Science Pipelines OperatorAll instancesCreate

这两种方式创建的是同一个资源;请选择最适合你工作流的方式。

前提条件

  • 已安装 Data Science Pipelines Operator,且其 CSV 报告为 Succeeded —— 参见 安装
  • 具备目标集群的 kubectl 访问权限(用于 CLI 方式和验证)。
  • 为 pipeline 栈准备一个目标项目 namespace(本指南使用 data-science-project)。

1. 选择数据库和对象存储

每个 DSPA 都需要一个数据库(用于 pipeline metadata)和一个兼容 S3 的对象存储(用于 pipeline artifacts)。你有两种选择:

  • 托管方式(最简单) —— 让 operator 在 DSPA namespace 中为你部署 MariaDB 和 MinIO。适合快速开始或自包含项目。

    WARNING

    托管的 MariaDB 和 MinIO 仅适用于开发和测试(它们是单实例,没有备份或 HA)。生产环境请使用外部后端。

  • 外部方式 —— 将 DSPA 指向你自己的 MySQL 和兼容 S3 的存储。推荐用于生产环境(你可以自行控制备份、HA 和规格)。

对于外部部署,请先创建凭证 secrets:

kubectl create namespace data-science-project

# database password
kubectl -n data-science-project create secret generic dspa-db \
  --from-literal=password='<db-password>'

# object-storage access + secret keys
kubectl -n data-science-project create secret generic dspa-s3 \
  --from-literal=accesskey='<s3-access-key>' \
  --from-literal=secretkey='<s3-secret-key>'

2. 创建 DSPA

方式 A — 使用 kubectl

托管后端(快速开始): operator 会部署 MariaDB + MinIO。

apiVersion: datasciencepipelinesapplications.opendatahub.io/v1
kind: DataSciencePipelinesApplication
metadata:
  name: sample
  namespace: data-science-project
spec:
  dspVersion: v2
  apiServer:
    enableSamplePipeline: false
  objectStorage:
    minio:
      deploy: true
  # database omitted → the operator deploys a managed MariaDB

外部后端(生产环境): 指向你自己的 MySQL 和 S3。

apiVersion: datasciencepipelinesapplications.opendatahub.io/v1
kind: DataSciencePipelinesApplication
metadata:
  name: sample
  namespace: data-science-project
spec:
  dspVersion: v2
  apiServer:
    enableOauth: false
    enableSamplePipeline: false
  workflowController:
    deploy: true
  mlmd:
    deploy: true
  database:
    externalDB:
      host: mysql.example.com
      port: "3306"
      username: root
      pipelineDBName: mlpipeline
      passwordSecret:
        name: dspa-db
        key: password
  objectStorage:
    externalStorage:
      host: s3.example.com
      port: "8333"
      scheme: http
      bucket: mlpipeline
      s3CredentialsSecret:
        secretName: dspa-s3
        accessKey: accesskey
        secretKey: secretkey

保存为 dspa.yaml 并应用:

kubectl apply -f dspa.yaml

方式 B — 使用 Alauda Console UI

  1. Administrator 视图中,进入 MarketplaceOperatorHub
  2. 在顶部的 Cluster 下拉列表中,选择目标集群。
  3. 打开已安装的 Data Science Pipelines Operator
  4. 切换到 All instances 选项卡并点击 Create(如有提示,选择 DataSciencePipelinesApplication)。
  5. 填写表单,或切换到 YAML 视图并粘贴方式 A 中的某个清单。将 Namespace 设置为你的项目 namespace(例如 data-science-project)。
  6. 点击 Create

此时该实例会出现在 All instances 下;其状态会反映 DSPA 的就绪情况(请参见下一步)。

3. 验证 DSPA 是否就绪

# Ready=True means all components reconciled
kubectl -n data-science-project get dspa sample \
  -o jsonpath='{range .status.conditions[*]}{.type}={.status}{"\n"}{end}'

# the component pods are Running
kubectl -n data-science-project get pods -l component=data-science-pipelines

你应该会看到 Ready=True,并且 ds-pipeline-* pods(APIServer、persistence agent、scheduled-workflow、workflow controller、MLMD)处于 Running 状态。

4. 使用 pipeline 栈(KFP v2 SDK)

DSPA 的 APIServer 可在集群内通过 http://ds-pipeline-<name>.<namespace>.svc:8888 访问——这里是 http://ds-pipeline-sample.data-science-project.svc:8888。使用 kfp Python SDK 编译并上传 pipeline(可从 pod 中执行,或从能够访问该 Service 的机器上执行):

import kfp
from kfp import dsl

@dsl.component(base_image="python:3.12-slim")
def hello(msg: str) -> str:
    return msg

@dsl.pipeline(name="hello-pipeline")
def hello_pipeline(msg: str = "hello"):
    hello(msg=msg)

client = kfp.Client(
    host="http://ds-pipeline-sample.data-science-project.svc:8888",
    namespace="data-science-project",
)

# compile + upload the pipeline
kfp.compiler.Compiler().compile(hello_pipeline, package_path="hello.yaml")
uploaded = client.upload_pipeline("hello.yaml", pipeline_name="hello-pipeline")
print("uploaded pipeline:", uploaded.pipeline_id)

# confirm it is listed
for p in client.list_pipelines(page_size=10).pipelines or []:
    print(" -", p.display_name, p.pipeline_id)

如果你安装 operator 时设置了 EXTERNAL_ROUTE_PROVIDER=virtualservice,那么 DSPA 的 status.components.apiServer.externalUrl 也会提供一个通过共享 Istio gateway 访问的外部路径。

清理

kubectl -n data-science-project delete dspa sample

删除 DSPA 会移除其创建的 pipeline 栈。在使用托管后端时,托管的 MariaDB/MinIO(及其数据)也会一并删除;外部后端则不会受到影响。