Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs 菜单
Docs 主页
/ /
MongoDB Atlas Kubernetes Operator
/

Helm Charts 快速入门

您可以使用 Atlas Kubernetes Operator 管理 Atlas 中的资源,而无需离开 Kubernetes。本教程演示如何在 Atlas 中使用 Atlas Kubernetes Operator 从 Helm Charts 创建第一个集群。

注意

您希望在没有 Helm 的情况下开始吗?

要使用Atlas Kubernetes Operator从Kubernetes配置文件在Atlas中创建第一个集群,请参阅快速入门。

本教程要求:

  • 正在运行的 Kubernetes 集群,其节点运行 x86-64、AMD64 或 ARM64 架构的处理器。

您可以访问 GitHub 上的 Atlas Kubernetes Operator 项目:

  • https://github.com/mongodb/mongodb-atlas-kubernetes

重要

自定义资源不再默认删除对象

1

注册新的 Atlas 帐户登录您的 Atlas 帐户。

2

注意

您需要以下公共 API 密钥、私有 API 密钥和组织 ID 信息, 配置 Atlas Kubernetes Operator 对 Atlas 的访问权限。

向组织授予编程访问权限并配置API Access List

您需要以下公共 API 密钥、私有 API 密钥和组织 ID 信息, 配置 Atlas Kubernetes Operator 对 Atlas 的访问权限。

3

运行以下其中一组命令:

  • 如果您希望 Atlas Kubernetes Operator 监视 Kubernetes 集群中的所有命名空间,请运行以下命令:

    helm repo add mongodb https://mongodb.github.io/helm-charts
    helm install atlas-operator --namespace=atlas-operator --create-namespace mongodb/mongodb-atlas-operator
  • 如果您希望 Atlas Kubernetes Operator 仅监视自己的命名空间,请将 --watchNamespaces 标志设立为其自己的命名空间,然后运行以下命令:

    注意

    您只能将 --watchNamespaces 标志设立为其自己的命名空间。目前不支持将 --watchNamespaces 标志设置为任何其他命名空间

    helm install atlas-operator --namespace=atlas-operator --set watchNamespaces=atlas-operator --create-namespace mongodb/mongodb-atlas-operator
4
  1. 自定义 Atlas 项目及其数据库用户。

    创建名为 install-values.yaml 的文件并粘贴以下示例代码,该代码将执行以下操作:

    • 将项目名称设置为 My Project

    • 允许所有 IP 地址 (0.0.0.0) 访问项目。

    • 创建一个名为dbadmin且具有dbAdmin角色的数据库用户。

    • 创建一个名为dbuser且具有readWrite角色的数据库用户。

    project: # Project custom values
    atlasProjectName: "My Project"
    projectIpAccessList:
    - cidrBlock: "0.0.0.0/0"
    users: # Custom database users
    - username: dbadmin
    databaseName: admin
    roles:
    - databaseName: admin-role
    roleName: dbAdmin
    - username: dbuser
    databaseName: admin
    roles:
    - databaseName: user-role
    roleName: readWrite
  2. 运行以下命令。

    以下命令中的 --set--values 标志使用您的组织 ID、API 密钥和 Atlas 项目配置覆盖 Values.yaml 文件值和默认 Helm Charts 值。

    注意

    mongodb/atlas-deployment 引用存储库中图表的名称。

    helm install atlas-deployment \
    mongodb/atlas-deployment \
    --namespace=my-cluster \
    --create-namespace \
    --set atlas.secret.orgId='<orgid>' \
    --set atlas.secret.publicApiKey='<publicKey>' \
    --set atlas.secret.privateApiKey='<privateApiKey>' \
    --values install-values.yaml

    要了解可用参数的更多信息,请参阅 AtlasDeployment 自定义资源。

    要创建无服务器实例,请参阅无服务器实例示例

5

运行以下命令,等待 dbadmin 数据库用户准备就绪:

kubectl wait --for=condition=ready --timeout=10m -n my-cluster atlasdatabaseusers/atlas-deployment-dbadmin

注意

AtlasDatabaseUser 自定义资源等待数据库部署就绪。创建新的数据库部署最多可能需要 10 分钟。

6

重要

以下命令需要 jq 1.6 或更高版本。

运行以下命令检索 dbadmin 数据库用户的连接字符串和密码。您的连接字符串将与示例输出不同。

kubectl get secret -n my-cluster my-project-cluster-name-dbadmin -ojson | jq -r '.data | with_entries(.value |= @base64d)';
{
"connectionStringStandard": "mongodb://admin-user:%25SomeLong%25password$foradmin@atlas-cluster-shard-00-00.nlrvs.mongodb.net:27017,atlas-cluster-shard-00-01.nlrvs.mongodb.net:27017,atlas-cluster-shard-00-02.nlrvs.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-11q9bn-shard-0",
"connectionStringStandardSrv": "mongodb+srv://admin-user:%25SomeLong%25password$foradmin@atlas-cluster.nlrvs.mongodb.net",
"password": "%SomeLong%password$foradmin",
"username": "dbadmin"
}

您可以在应用程序中使用以下密钥

containers:
- name: test-app
env:
- name: "CONNECTION_STRING"
valueFrom:
secretKeyRef:
name: my-project-cluster-name-dbadmin
key: connectionStringStandardSrv

后退

验证包的完整性

在此页面上