Docs 菜单
Docs 主页
/
MongoDB Enterprise Kubernetes Operator

Kubernetes Operator 快速入门

在此页面上

重要

本部分仅适用于单个Kubernetes集群部署。 对于多 Kubernetes集群MongoDB部署,请参阅多 Kubernetes 集群快速入门

MongoDB Enterprise Kubernetes Operator 使用Kubernetes API和工具来管理在Kubernetes集群中运行的MongoDB集群。 Kubernetes Operator 与MongoDB Cloud Manager或MongoDB Ops Manager协同工作。 本教程演示如何使用Kubernetes Operator 在MongoDB Cloud Manager中部署和连接第一个MongoDB副本集。 您可以使用 Kind 来快速设立集群。要学习;了解更多信息,请参阅 Kind

本教程要求:

1
helm repo add mongodb https://mongodb.github.io/helm-charts
2

要安装Kubernetes Operator with Helm,请参阅存储库中的说明。

例子

以下命令使用可选的 --create-namespace 选项在 mongodb 命名空间中安装 MongoDB Enterprise Kubernetes Operator。默认情况下,Kubernetes Operator 使用 default 命名空间。

helm install enterprise-operator mongodb/enterprise-operator --namespace mongodb --create-namespace
3

如果您尚未执行,请运行以下命令,执行所创建命名空间的所有 kubectl 命令:

kubectl config set-context $(kubectl config current-context) --namespace=mongodb
4
  1. 转到 Cloud Manager UI 中的 Kubernetes 设置页面。

  2. 单击 Create New API KeysUse Existing API Keys

  3. 填写表格。 要了解更多信息,请参阅对 Cloud Manager 的编程访问。

  4. 单击 Generate Key and YAML(连接)。

5

复制并保存生成的 config-map.yaml 文件。

示例:

apiVersion: v1
kind: ConfigMap
metadata:
name: my-project
namespace: mongodb
data:
baseUrl: https://cloud.mongodb.com
projectName: my-project # this is an optional parameter
orgId: 5ecd252f8c1a75033c74106c # this is a required parameter

要了解更多信息,请参阅参数说明。

6

复制并保存生成的 secret.yaml 文件。

示例:

apiVersion: v1
kind: Secret
metadata:
name: organization-secret
namespace: mongodb
stringData:
user: <public_key>
publicAPIKey: <private_key>

出于安全目的,MongoDB Cloud Manager 仅显示该文件一次。

7

运行以下命令:

kubectl apply -f secret.yaml -f config-map.yaml
8
  1. 复制并保存以下 YAML 文件:

    apiVersion: mongodb.com/v1
    kind: MongoDB
    metadata:
    name: demo-mongodb-cluster-1
    namespace: mongodb
    spec:
    members: 3
    version: 4.4.5-ent
    type: ReplicaSet
    security:
    authentication:
    enabled: true
    modes: ["SCRAM"]
    cloudManager:
    configMapRef:
    name: my-project
    credentials: organization-secret
    persistent: true
    podSpec:
    podTemplate:
    spec:
    containers:
    - name: mongodb-enterprise-database
    resources:
    limits:
    cpu: 2
    memory: 1.5G
    requests:
    cpu: 1
    memory: 1G
    persistence:
    single:
    storage: 10Gi
  2. 运行以下命令:

    kubectl apply -f <replica-set-conf>.yaml
9

您可以选择使用明文密码或 Base64 编码密码。明文密码使用 stringData.password,Base64 编码密码使用 data.password

注意

提供以下参数的值。要了解更多信息,请参阅参数说明。

对于明文密码,创建并保存以下 YAML 文件:

apiVersion: v1
kind: Secret
metadata:
name: mms-user-1-password
# corresponds to user.spec.passwordSecretKeyRef.name
type: Opaque
stringData:
password: <my-plain-text-password>
# corresponds to user.spec.passwordSecretKeyRef.key

对于 Base64 编码密码,创建并保存以下 YAML 文件:

apiVersion: v1
kind: Secret
metadata:
name: mms-user-1-password
# corresponds to user.spec.passwordSecretKeyRef.name
type: Opaque
data:
password: <base-64-encoded-password>
# corresponds to user.spec.passwordSecretKeyRef.key
10
  1. 复制并保存以下 MongoDB 用户资源规范 文件:

    apiVersion: mongodb.com/v1
    kind: MongoDBUser
    metadata:
    name: mms-scram-user-1
    spec:
    passwordSecretKeyRef:
    name: mms-user-1-password
    # Match to metadata.name of the User Secret
    key: password
    username: "mms-scram-user-1"
    db: "admin" #
    mongodbResourceRef:
    name: "demo-mongodb-cluster-1"
    # Match to MongoDB resource using authenticaiton
    roles:
    - db: "admin"
    name: "clusterAdmin"
    - db: "admin"
    name: "userAdminAnyDatabase"
    - db: "admin"
    name: "readWrite"
    - db: "admin"
    name: "userAdminAnyDatabase"
  2. 运行以下命令:

    kubectl apply -f <database-user-conf>.yaml
11

您可以在 Cloud Manager 或 Ops Manager 中查看新创建的用户:

  1. 从项目的 Deployment 视图中,点击 Security 选项卡。

  2. 单击 MongoDB Users 嵌套标签页。

12

Cloud Manager 应用程序中执行以下步骤:

  1. 单击左侧导航栏中的 Deployment

  2. 单击要连接到的部署的

  3. 单击 Connect to this instance(连接)。

  4. 在终端中运行连接命令,以连接到部署。

后退

MongoDB Enterprise Kubernetes Operator