> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 在安装中使用现有密钥（Kubernetes）

默认情况下，LangSmith 会创建多个 Kubernetes 密钥来存储敏感信息，例如许可证密钥、盐值和其他配置参数。但是，您可能希望使用已在 Kubernetes 集群中创建的现有密钥（或通过某种密钥操作器进行配置）。如果您希望以集中方式管理敏感信息，或者有特定的安全要求，这可能会很有用。

默认情况下，我们将创建以下与 LangSmith 不同组件对应的密钥：

* `langsmith-secrets`：此密钥包含许可证密钥和其他一些基本配置参数。要开始使用，请参考[密钥模板](https://github.com/langchain-ai/helm/blob/main/charts/langsmith/templates/secrets.yaml)。
* `langsmith-redis`：此密钥包含 Redis 连接字符串（或使用 Redis 集群时的节点 URI）和密码。要开始使用，请参考[Redis 密钥模板](https://github.com/langchain-ai/helm/blob/main/charts/langsmith/templates/redis/secrets.yaml)。
* `langsmith-postgres`：此密钥包含 Postgres 连接字符串和密码。要开始使用，请参考[Postgres 密钥模板](https://github.com/langchain-ai/helm/blob/main/charts/langsmith/templates/postgres/secrets.yaml)。
* `langsmith-clickhouse`：此密钥包含 ClickHouse 连接字符串和密码。要开始使用，请参考[ClickHouse 密钥模板](https://github.com/langchain-ai/helm/blob/main/charts/langsmith/templates/clickhouse/secrets.yaml)。

## 要求

* 现有的 Kubernetes 集群
* 在集群中创建 Kubernetes 密钥的方法。可以使用 `kubectl`、Helm 图表或密钥操作器（如 [Sealed Secrets](https://github.com/bitnami-labs/sealed-secrets)）来完成

## 参数

您需要创建自己的 Kubernetes 密钥，其结构需符合 LangSmith Helm 图表所配置的密钥结构。

<Warning>
  密钥的结构必须与 LangSmith Helm 图表所配置的密钥相同（请参考上面的链接查看具体密钥）。如果缺少任何必需的键，您的 LangSmith 实例可能无法正常工作。
</Warning>

示例密钥可能如下所示：

```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
apiVersion: v1
kind: Secret
metadata:
  name: langsmith-existing-secrets
  namespace: langsmith
stringData:
  oauth_client_id: foo
  oauth_client_secret: foo
  oauth_issuer_url: foo
  langsmith_license_key: foo
  langgraph_cloud_license_key: foo
  api_key_salt: foo
  jwt_secret: foo
  initial_org_admin_password: foo
  blob_storage_access_key: foo
  blob_storage_access_key_secret: foo
  azure_storage_account_key: foo
  azure_storage_connection_string: foo
  fleet_encryption_key: foo
  insights_encryption_key: foo
```

## 配置

配置好这些密钥后，您可以配置 LangSmith 实例直接使用这些密钥，以避免通过明文传递密钥值。您可以通过修改 LangSmith Helm 图表安装的 `langsmith_config.yaml` 文件来实现。

```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
config:
  existingSecretName: "langsmith-secrets" # 包含许可证密钥和其他基本配置参数的密钥名称
redis:
  external:
    enabled: true # 设置为 true 以使用外部 Redis 实例。仅在使用外部 Redis 实例时才需要此密钥
    existingSecretName: "langsmith-redis" # 包含 Redis 连接字符串和密码的密钥名称
postgres:
  external:
    enabled: true # 设置为 true 以使用外部 Postgres 实例。仅在使用外部 Postgres 实例时才需要此密钥
    existingSecretName: "langsmith-postgres" # 包含 Postgres 连接字符串和密码的密钥名称
clickhouse:
  external:
    enabled: true # 设置为 true 以使用外部 ClickHouse 实例。仅在使用外部 ClickHouse 实例时才需要此密钥
    existingSecretName: "langsmith-clickhouse" # 包含 ClickHouse 连接字符串和密码的密钥名称
```

配置完成后，您需要更新 LangSmith 安装。您可以按照[升级指南](/langsmith/self-host-upgrades)操作。如果一切配置正确，您的 LangSmith 实例现在应该可以通过 Ingress 访问。您可以运行以下命令来检查密钥是否正确使用：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
kubectl describe deployment langsmith-backend | grep -i <secret-name>
```

您应该在输出中看到类似以下内容：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
POSTGRES_DATABASE_URI:                    <set to the key 'connection_url' in secret <your-secret-name>  Optional: false
CLICKHOUSE_DB:                            <set to the key 'clickhouse_db' in secret <your-secret-name>   Optional: false
```

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\langsmith\self-host-using-an-existing-secret.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
