部署 TrustyAI Service

TrustyAI Service (TAS) 会与 KServe 模型一起部署,并收集其推理数据,漂移检测和偏差指标就是基于这些数据计算的。本页面会创建 TrustyAIService 资源;有关数据摄取以及为其注册指标的内容,请参阅 Monitor 章节中的 Bias and Drift Monitoring

前提条件

  • 已安装 TrustyAI Operator(请参阅 Install TrustyAI)。
  • 如果使用 storage.format: DATABASE,则需要一个 MySQL 8.x 数据库。
  • 如果使用 storage.format: PVC,请确保集群具有可用的默认 StorageClass(由 CSI driver 提供支持),用于动态卷供应,这样 operator 创建的 PVC 才能成功绑定。

部署 TrustyAIService

请选择一种存储布局:DATABASE(MySQL)或 PVC(卷上的本地文件存储)。下面两个小节是替代方案,不是同一流程中的步骤。

DATABASE 模式

MySQL 凭据 Secret

在使用 storage.format: DATABASE 时,创建一个包含 TAS 部署所需键值的 secret:

apiVersion: v1
kind: Secret
metadata:
  name: <tas-name>-db-credentials
  namespace: <your-namespace>
type: Opaque
stringData:
  databaseKind: mysql
  databaseUsername: <username>
  databasePassword: <password>
  databaseService: <mysql-service-name>
  databasePort: "3306"
  databaseName: <db-name>
  # Database schema generation strategy used by TrustyAI when connecting to the database.
  # It controls what TAS does to the database schema (tables) during startup:
  # - none: do not manage schema
  # - create: create schema from scratch
  # - drop-and-create: drop existing schema, then create
  # - drop: drop existing schema
  # - update: update schema to match the expected model
  # - validate: only validate that the schema matches the expected model
  #
  # Default: update
  databaseGeneration: update

说明:

  • databaseName 引用的 MySQL schema(database)必须预先创建。TAS 不会自行创建数据库。
  • 数据库必须能够从 TAS pod 访问到。
  • databaseGeneration 控制 TAS 启动时如何处理 schema 变更。

TrustyAIService CR

示例:

apiVersion: trustyai.opendatahub.io/v1
kind: TrustyAIService
metadata:
  name: <tas-name>
  namespace: <your-namespace>
  annotations:
    trustyai.cpaas.io/monitor-enable: "true"
    trustyai.cpaas.io/monitor-interval: "30s"
    trustyai.cpaas.io/monitor-metric-regex: "^trustyai_.*"
spec:
  storage:
    format: DATABASE
    databaseConfigurations: <tas-name>-db-credentials
  metrics:
    schedule: "5s"
    batchSize: 5000
  replicas: 1

DATABASE 模式下,storage.databaseConfigurations 必须设置为上面创建的 MySQL 凭据 Secret 的名称,并且该 Secret 需要与 TrustyAIService 位于同一 namespace 中。

metadata.annotations 是可选的,用于允许 operator 创建 ServiceMonitor,以供 Prometheus 抓取(从而使平台能够自动收集监控数据)。

  • 当设置 trustyai.cpaas.io/monitor-enable: "true" 时,operator 会生成一个 ServiceMonitor
  • trustyai.cpaas.io/monitor-intervaltrustyai.cpaas.io/monitor-metric-regex 是可选项;未提供时,operator 会使用默认值。

trustyai.cpaas.io/monitor-interval 控制 Prometheus 抓取 TAS 指标的频率(默认值:30s)。 trustyai.cpaas.io/monitor-metric-regex 控制抓取后保留哪些指标名称(默认值:^trustyai_.*)。

spec.metrics 字段:

  • schedule(必填):TAS 执行指标计算的频率(例如每 5s 一次)。该值为持续时间字符串。
  • batchSize(可选):TAS 在每次指标计算中包含多少条推理记录(值越大,每次运行使用的数据越多)。如果未设置,operator 会使用默认值 5000

PVC 模式

storage.formatPVC(无需 MySQL Secret)时,使用此路径。示例:

apiVersion: trustyai.opendatahub.io/v1
kind: TrustyAIService
metadata:
  name: <tas-name>
  namespace: <your-namespace>
spec:
  storage:
    format: PVC
    folder: /inputs
    size: 1Gi
  data:
    filename: data.csv
    format: CSV
  metrics:
    schedule: "5s"
    batchSize: 5000
  replicas: 1

PVC 模式下:

  • storage.folder:TAS 在已挂载 PVC 中存储和读取数据的路径。
  • storage.size:请求的 PVC 容量(例如 1Gi)。
  • operator 会自动在与 TrustyAIService 相同的 namespace 中创建名为 <tas-name>-pvc 的 PVC。由于该 PVC 使用集群默认 StorageClass(未显式设置 storageClassName),因此集群应提供可用的默认 StorageClass(否则 PVC 可能会一直处于 Pending 状态)。

当所选模式的 TrustyAIService manifest 准备就绪后,应用它(同一命令适用于 DATABASEPVC YAML):

kubectl apply -f <trustyai-service>.yaml -n <your-namespace>

验证部署就绪情况

kubectl get trustyaiservices -n <your-namespace> <tas-name>

预期的 status.phase 应为 Ready

同时检查 pods:

kubectl get pods -n <your-namespace> -l app.kubernetes.io/instance=<tas-name>

下一步

当服务处于 Ready 状态后,继续阅读 Bias and Drift Monitoring,以摄取 reference 和 live 推理数据、注册漂移和偏差指标,并将其暴露给 Prometheus。