安装 Label Studio

本文档详细介绍了如何将 Label Studio 部署到 Kubernetes 集群及常用配置参数。

下载

下载 Label Studio 安装包:label-studio.ALL.xxxx.tgz

使用 violet 命令发布到平台仓库:

violet push --platform-address=platform-access-address --platform-username=platform-admin --platform-password=platform-admin-password label-studio.ALL.xxxx.tgz

部署

准备存储

Label Studio 将数据存储在数据库中,需要持久化存储。集群需预装 CSI 或预先准备好 PersistentVolume

准备数据库

Label Studio 支持以下数据库:

  • PostgreSQL:版本 13 及以上

可使用 Data Services 提供的 PostgreSQL operator 创建 PostgreSQL 集群

Data Services 中查看 PostgreSQL 实例详情,获取访问地址和密码。

准备 Redis(可选)

Redis 非必需,但推荐用于生产环境。

可使用 Data Services 创建 Redis 实例。

注意: Label Studio 仅支持访问 standalone 模式的 Redis。

  • 创建 standalone 模式的 Redis

    1. 创建 Redis 实例时,Architecture 选择 Redis Sentinel

    2. 设置完所有参数后,切换到 YAML 模式,将 spec.arch 修改为 standalone,然后点击 Create 按钮。

    3. 创建完成后,切换到 Alauda Container Platform 视图,找到名为 rfr-<Redis 实例名>-read-writeService,该 Service 即为此 Redis 实例的访问地址。

创建原生应用

  1. 进入 Alauda Container Platform 视图,选择 Label Studio 部署的命名空间。

  2. 左侧导航选择 Applications / Applications,然后点击右侧页面的 Create 按钮。

  3. 弹出对话框中选择 Create from Catalog,页面跳转至 Catalog 视图。

  4. 找到 3rdparty/chart-label-studio,点击 Create 创建该原生应用。

  5. Catalog / Create label-studio 表单中填写 Name(建议为 label-studio)和 Values 中的 Custom 配置,点击 Create 按钮完成创建。Custom 内容将在下文说明,创建后也可通过 Update 应用方式修改。

配置

用户可修改原生应用的 Custom Values 以调整配置,主要关注以下配置项:

1. 配置存储

1.1 配置存储类和存储大小

可通过添加以下配置指定存储类:

label-studio:
  persistence:
    storageClass: storage-class-name
    size: 20Gi                               # 替换为实际所需空间大小

2. 配置数据库

2.1 配置 PostgreSQL

通过设置以下字段配置 PostgreSQL 访问信息:

global:
  pgConfig:
    host: localhost                          # PostgreSQL 访问地址
    port: 5432                               # PostgreSQL 访问端口,默认:5432
    dbName: labelstudio                      # 数据库名称,注意:数据库会自动创建
    userName: postgres                       # 数据库用户名
    password:
      secretName: postgre-secret             # 存储数据库访问密码的 Secret 名称
      secretKey: password                    # 存储数据库访问密码的 Secret Key

2.2 配置 Redis

通过设置以下字段配置 Redis 访问信息:

global:
  redisConfig:
    host: "redis://your-redis-host:6379/1"    # Redis 连接地址,格式:redis://[:password]@host:port/db
    password:                                 # 可选,密码可包含在 host 中或通过 Secret 单独提供
      secretName: "redis-secret"              # 存储 Redis 访问密码的 Secret 名称
      secretKey: "password"                   # 存储 Redis 密码的 Secret Key
    ssl:                                      # 可选
      redisSslCertReqs: "optional"            # SSL 证书要求:"" 表示不要求,"optional"、"required"
      redisSslSecretName: "redis-ssl-secret"  # SSL 证书 Secret 名称
      redisSslCaCertsSecretKey: "ca.crt"      # CA 证书 Secret Key
      redisSslCertFileSecretKey: "tls.crt"    # 客户端证书 Secret Key
      redisSslKeyFileSecretKey: "tls.key"     # 客户端私钥 Secret Key

3. 配置访问方式

默认使用 LoadBalancer 提供访问地址。

3.1 修改 Service 类型

通过设置以下字段修改 Service 类型:

label-studio:
  app:
    service:
      type: LoadBalancer                     # 可改为 NodePort 或 ClusterIP

3.2 启用 Ingress

通过设置以下字段配置 Ingress,启用后通常将 Service 类型改为 ClusterIP:

label-studio:
  app:
    ingress:
      enabled: true                          # 启用 Ingress 功能
      host: localhost                        # 访问域名(必须为 DNS 名称,不能是 IP 地址)
      tls:
        - secretName: certificate-secret     # 存储 TLS 证书的 Secret 名称
global:
  extraEnvironmentVars:
    LABEL_STUDIO_HOST: https://x.x.x.x       # 前端资源加载的 Web 访问 URL

3.3 配置 OAuth2 Proxy(可选)

oauth2_proxy:
  enabled: true
  oidcIssuer: "https://x.x.x.com/dex"          # OIDC Issuer 地址
  oidcClientID: "your-client-id"               # OIDC 客户端 ID
  oidcClientSecret: "your-client-secret"       # OIDC 客户端密钥(建议使用 Secret)

  ingress:                                     # 可选,使用 ingress 访问 OAuth2 proxy
    enabled: true                              # 默认 false
    host: localhost                            # 访问域名,必须设置,不能使用 IP,只能是域名
    tls:
      - secretName: certificate-secret         # 存储 TLS 证书的 Secret 名称

如果想将 Alauda Container Platform 配置为 OIDC Provider,配置如下:

  • oauth2_proxy.oidcIssuer 为平台访问地址加 /dex
  • oauth2_proxy.oidcClientID 固定为 label-studio
  • oauth2_proxy.oidcClientSecret 固定为 ZXhhbXBsZS1hcHAtc2VjcmV0

还需在 global 集群创建 OAuth2Client 资源,配置 Label Studio 的客户端信息:

apiVersion: dex.coreos.com/v1
kind: OAuth2Client
metadata:
  name: nrqwezlmfvzxi5lenfx4x4u44scceizf
  namespace: cpaas-system
id: label-studio                                # 必须与 values 中 oauth2_proxy.oidcClientID 一致
name: Label Studio
secret: ZXhhbXBsZS1hcHAtc2VjcmV0                # 必须与 values 中 oauth2_proxy.oidcClientSecret 一致
redirectURIs:
- http://xxx.xxx.xxxx.xxx:xxxxx/*               # OAuth2-Proxy 访问地址,见下文获取方式
                                                # 若部署多个 Label Studio 实例,需将所有访问地址添加在此

注意:OAuth2 proxy 访问地址可从 <Application Name>-oauth2-proxy Service 获取,根据 Service 类型选择合适的访问方式。

4. 配置用户管理

4.1 禁用用户注册

通过设置以下字段禁用用户注册:

global:
  extraEnvironmentVars:
    LABEL_STUDIO_DISABLE_SIGNUP_WITHOUT_LINK: true

访问地址

1. 通过 Service 访问

Label Studio 通过 Service 提供外部访问,查看其 Service 获取访问地址。

  • 未启用 OAuth2 proxy 时,Service 名称为:<Application Name>-ls-app
  • 启用 OAuth2 proxy 时,Service 名称为:<Application Name>-oauth2-proxy

Service 类型为 LoadBalancer,且环境中的负载均衡控制器已分配访问地址,请通过该地址访问。

LoadBalancerNodePort 类型的 Service 也可通过 节点 IP 和其 NodePort 访问。

2. 通过 Ingress 访问

启用 Ingress 后,请通过配置的 LABEL_STUDIO_HOST 访问。

用户管理

Label Studio 无默认用户名和密码,用户可在登录页填写邮箱和密码完成新用户注册。

注意

  • 默认配置允许任何人注册新用户
  • 所有用户权限相同,可访问所有项目
  • 若需限制用户注册,请配置环境变量 LABEL_STUDIO_DISABLE_SIGNUP_WITHOUT_LINK=true,详见:4.1 禁用用户注册