安装 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 cluster

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 应用方式进行修改。

配置

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

1. 配置存储

1.1 配置 Storage Class 和存储大小

可以通过添加以下配置来指定 Storage Class:

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。启用 Ingress 后,Service 类型通常会改为 ClusterIP(虚拟 IP):

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-proxyService 中获取,请根据 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 禁用用户注册