Docs 菜单
Docs 主页
/
MongoDB Enterprise Kubernetes Operator
/

OpenShift 快速入门

在此页面上

重要

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

MongoDB Enterprise Kubernetes Operator 使用 Kubernetes API 和工具来管理 MongoDB 集群。Kubernetes Operator 与 MongoDB Cloud Manager 或 Ops Manager 协同工作。本教程演示如何使用 Kubernetes Operator 从 OpenShift 在 Cloud Manager 或 Ops Manager 中部署和连接第一个副本集。

本教程要求:

  • 正在运行的 Cloud Manager 或 Ops Manager 集群。

1
git clone https://github.com/mongodb/mongodb-enterprise-kubernetes.git
2

默认情况下,Kubernetes Operator 使用 mongodb命名空间。 为了简化安装,请考虑使用以下mongodb kubectl 创建一个标记为 的命名空间 命令:

kubectl create namespace mongodb
3

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

kubectl config set-context $(kubectl config current-context) --namespace=mongodb
4
  1. 调用以下 oc 命令针对 MongoDB 部署安装 CustomResourceDefinitions

    oc apply -f crds.yaml
  2. <openshift-pull-secret> 添加到 MongoDB Enterprise Kubernetes Operator YAML 文件的 ServiceAccount 定义中。

    ---
    # Source: mongodb-enterprise-operator/templates/serviceaccount.yaml
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
    name: enterprise-operator
    namespace: mongodb
    imagePullSecrets:
    - name: <openshift-pull-secret>
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
    name: mongodb-enterprise-appdb
    namespace: mongodb
    imagePullSecrets:
    - name: <openshift-pull-secret>
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
    name: mongodb-enterprise-database-pods
    namespace: mongodb
    imagePullSecrets:
    - name: <openshift-pull-secret>
  3. 调用以下 oc 命令安装 Kubernetes Operator:

    oc apply -f mongodb-enterprise-openshift.yaml
5

运行以下命令:

注意

为以下参数提供公钥和私钥值。如需了解更多信息,请参阅“创建 Kubernetes Operator 的档案”。

kubectl -n mongodb \
create secret generic ops-manager-admin-key \
--from-literal="publicKey=<publicKey>" \
--from-literal="privateKey=<privateKey>"
6
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: my-project
namespace: mongodb
data:
projectName: myProjectName # this is an optional parameter; when omitted, the Operator creates a project with the resource name
orgId: 5b890e0feacf0b76ff3e7183 # this is a required parameter
baseUrl: https://ops.example.com:8443
EOF
类型
说明
例子
metadata.name
字符串

Kubernetes 对象的名称。

资源名称必须少于或等于 44 个字符。

要学习;了解更多信息,请参阅有关 名称 的Kubernetes文档 。此名称必须遵循 RFC1123 命名规则,仅使用小写字母数字字符-. ,并且必须以字母数字字符开头和结尾。

my-project
metadata.namespace
字符串
Kubernetes 命名空间 Kubernetes Operator 在其中创建此MongoDB 资源和其他 对象
mongodb
data.projectName
字符串

MongoDB Ops Manager项目的标签。

如果 项目不存在,KubernetesMongoDB Ops Manager Operator 会创建该项目。如果省略projectName ,Kubernetes Operator 将创建一个与 Kubernetes 资源同名的项目。

要使用 Cloud Manager 或 Ops Manager 组织中的现有项目,请找到projectName ,方法是单击 Cloud Manager 或 Ops Manager 页面左上角的 All Clusters链接,然后在Search框,或滚动以在列表中查找名称。 此列表中的每张卡片代表一个 Cloud Manager 或 Ops Manager组织项目的组合。

myProjectName
data.orgId
字符串

必需。 24 字符的十六进制string ,用于唯一标识您的Cloud Manager或MongoDB Ops Manager组织。

您可以使用 Kubernetes Operator 通过 Cloud Manager 和 Ops Manager 6.0.x 版或更高版本来部署 MongoDB 资源。

可以使用 Atlas Operator 将 MongoDB 资源部署到 Atlas。

指定现有组织:

  1. 查找该组织的 ID。

    点击左侧导航栏中的 Settings

  2. 将 orgId 复制并粘贴到 URL 中。

    选择您的组织,在浏览器中查看当前 URL,然后复制 <orgId> 占位符中显示的值,如下所示:

    https://ops.example.com:8443/ v2#/org/<orgId>/projects

必须具备组织项目创建者角色才能在现有 Cloud Manager 或 Ops Manager 组织中创建新项目。

如果您提供空字符串作为 orgId,Kubernetes Operator 会创建一个与您的项目同名的组织。

5b890e0feacf0b76ff3e7183
data.baseUrl
字符串

Ops Manager 应用程序的 URL,包括 FQDN 和端口号。

重要提示: 如果您使用MongoDB Ops Manager KubernetesOperator部署MongoDB Ops Manager MongoDBKubernetes,并且 将管理部署在其所部署到的 集群 外部 的 数据库资源,则必须设立data.baseUrl 设置为与spec.configuration.mms.centralUrl 中的MongoDB Ops Manager 设置相同的值 资源规范。要学习;了解更多信息,请参阅管理外部MongoDB部署。

如果使用 Cloud Manager,请将 data.baseUrl 值设置为 https://cloud.mongodb.com

https://ops.example.com:8443
7
  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
8

您可以选择使用明文密码或 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
9
  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
10

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

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

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

11

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

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

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

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

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

后退

OpenShift 教程