安装 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 instance name>-read-writeService,这就是该 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 应用方式进行修改。

配置

用户可以修改 ApplicationCustom Values 来调整配置。主要需要关注的配置如下:

1. 配置存储

1.1 配置 Storage Class 和存储大小

可以通过添加以下配置来指定 storage class:

label-studio:
  persistence:
    storageClass: storage-class-name
    size: 20Gi                               # Replace with the actual required space size

2. 配置数据库

2.1 配置 PostgreSQL

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

global:
  pgConfig:
    host: localhost                          # PostgreSQL access address
    port: 5432                               # PostgreSQL access port, default: 5432
    dbName: labelstudio                      # Database name, note: database will be created automatically
    userName: postgres                       # Database username
    password:
      secretName: postgre-secret             # Secret name storing database access password
      secretKey: password                    # Secret key storing database access password

2.2 配置 Redis

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

global:
  redisConfig:
    host: "redis://your-redis-host:6379/1"    # Redis connection address, format: redis://[:password]@host:port/db
    password:                                 # Optional, password can be included in host or provided separately via Secret
      secretName: "redis-secret"              # Secret name storing Redis access password
      secretKey: "password"                   # Secret key storing Redis password
    ssl:                                      # Optional
      redisSslCertReqs: "optional"            # SSL certificate requirements: "" means not required, "optional", "required"
      redisSslSecretName: "redis-ssl-secret"  # SSL certificate Secret name
      redisSslCaCertsSecretKey: "ca.crt"      # CA certificate Secret key
      redisSslCertFileSecretKey: "tls.crt"    # Client certificate Secret key
      redisSslKeyFileSecretKey: "tls.key"     # Client private key Secret key

3. 配置访问方式

默认使用 LoadBalancer 提供访问地址

3.1 修改 Service 类型

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

label-studio:
  app:
    service:
      type: LoadBalancer                     # Can be changed to NodePort or ClusterIP

3.2 启用 Ingress

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

label-studio:
  app:
    ingress:
      enabled: true                          # Enable Ingress functionality
      host: localhost                        # Access domain (must be DNS name, not IP address)
      tls:
        - secretName: certificate-secret     # Secret name storing TLS certificate
global:
  extraEnvironmentVars:
    LABEL_STUDIO_HOST: https://x.x.x.x       # Web access URL for frontend resource loading

3.3 配置 OAuth2 Proxy(可选)

oauth2_proxy:
  enabled: true
  oidcIssuer: "https://x.x.x.com/dex"          # OIDC Issuer address
  oidcClientID: "your-client-id"               # OIDC client ID
  oidcClientSecret: "your-client-secret"       # OIDC client secret (recommended to use Secret)

  ingress:                                     # Optional, use ingress to access OAuth2 proxy
    enabled: true                              # Default is false
    host: localhost                            # Access domain, must be set, cannot use IP address, only domain name
    tls:
      - secretName: certificate-secret         # Secret name storing TLS certificate

如果要将 Alauda Container Platform 配置为 OIDC Provider,请按如下方式配置:

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

还需要在 global cluster 中创建一个 OAuth2Client 资源,用于配置 Label Studio 的客户端信息:

apiVersion: dex.coreos.com/v1
kind: OAuth2Client
metadata:
  name: nrqwezlmfvzxi5lenfx4x4u44scceizf
  namespace: cpaas-system
id: label-studio                                # Must match oauth2_proxy.oidcClientID in values
name: Label Studio
secret: ZXhhbXBsZS1hcHAtc2VjcmV0                # Must match oauth2_proxy.oidcClientSecret in values
redirectURIs:
- http://xxx.xxx.xxxx.xxx:xxxxx/*               # OAuth2-Proxy access address, see below for how to obtain
                                                # If multiple Label Studio instances are deployed, add all access addresses here

注意: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,也可以通过 node IP 加上其 NodePort 进行访问。

2. 通过 Ingress 访问

如果启用了 Ingress,请通过配置的 LABEL_STUDIO_HOST 进行访问。

用户管理

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

注意

  • 默认配置允许任何人注册新用户
  • 所有用户具有相同的功能权限,并且可以访问所有项目
  • 如需限制用户注册,请配置环境变量 LABEL_STUDIO_DISABLE_SIGNUP_WITHOUT_LINK=true,参见:4.1 禁用用户注册