对于AI助手:文档索引位于 https://www.mongodb.com/zh-cn/docs/llms.txt — 通过将 .md 附加到任何URL路径,可以获得所有页面的降价版本。
Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs 菜单

OpenShift 快速入门

重要

本部分仅适用于单个 Kubernetes 集群部署。 对于多 Kubernetes 集群 MongoDB 部署,请参阅概述

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

本教程要求:

  • 正在运行的 Cloud Manager 或 Ops Manager 集群。
1
git clone https://github.com/mongodb/mongodb-kubernetes.git
2

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

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 Controllers for Kubernetes Operator YAML 文件的 ServiceAccount 定义中。

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

    oc apply -f mongodb-kubernetes-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 个字符。

此名称必须遵循 RFC1123 命名规范,仅包含小写字母数字字符或 -,并以字母数字字符开头和结尾。

要学习;了解更多信息,请参阅有关名称的Kubernetes文档。

my-project

metadata.namespace

字符串

Kubernetes Operator 在其中创建 资源和其他对象的Kubernetes命名空间。MongoDB

mongodb

data.projectName

字符串

MongoDB Ops Manager项目的标签。

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

如需使用 Cloud Manager 或 Ops Manager 组织中的现有项目,请单击 Cloud Manager 或 Ops Manager 页面左上方的 All Clusters 链接找到 projectName,然后在 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: 8.0.0
    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 authentication
    roles:
    - db: "admin"
    name: "clusterAdmin"
    - db: "admin"
    name: "userAdminAnyDatabase"
    - db: "admin"
    name: "readWrite"
  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. 在终端中运行连接命令,以连接到部署。