在默认配置中, MongoDB Agent MongoDB , MongoDB
您可以将MongoDB Ops Manager配置为在远程模式下运行,以便备份守护程序和托管MongoDB资源仅从MongoDB Ops Manager下载安装存档,MongoDB Ops Manager 将下载请求代理到本地 Web服务器或 S3 兼容存储上的HTTP端点部署到Kubernetes集群。
先决条件和注意事项
步骤
以下过程将 Nginx HTTP服务器部署到Kubernetes集群,以托管MongoDB安装存档。
将kubectl 配置为默认命名空间。
如果您尚未执行,请运行以下命令,执行所创建命名空间的所有 kubectl 命令。
注意
MongoDB Ops Manager如果要在多 Kubernetes 集群 部署中部署MongoDB 资源:
kubectl config set-context $(kubectl config current-context) --namespace=<metadata.namespace>为 Nginx 创建 ConfigMap。
本教程中的 ConfigMap 将 Nginx 配置为:
运行名为
localhost的 HTTP 服务器,侦听 Kubernetes 集群中节点上的端口80,然后将对特定资源的 HTTP 请求路由到提供 MongoDB Server 和 MongoDB Database Tools 安装存档的位置。
将以下示例 Nginx ConfigMap 粘贴到文本编辑器中:
apiVersion: v1kind: ConfigMapmetadata: name: nginx-confdata: nginx.conf: | events {} http { server { server_name localhost; listen 80; location /linux/ { alias /mongodb-ops-manager/mongodb-releases/linux/; } location /tools/ { alias /tools/; } } }以
.yaml文件扩展名保存此文件。通过对您创建的 ConfigMap 文件调用以下
kubectl命令来创建 Nginx ConfigMap:kubectl apply -f <nginix-configmap>.yaml
将 Nginx 部署到 Kubernetes 集群。
本教程中的 Nginx 资源配置:
部署一个 Nginx 副本,
创建卷挂载以存储 MongoDB Server 和 MongoDB database Tools 安装存档,以及
定义init 容器,该容器使用
curl命令将 Nginx 提供的安装存档下载到您在Kubernetes集群中部署的MongoDB数据库资源。
将以下示例 Nginx 资源配置粘贴到文本编辑器中:
apiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - image: nginx:1.14.2 imagePullPolicy: IfNotPresent name: nginx ports: - containerPort: 80 volumeMounts: - mountPath: /mongodb-ops-manager/mongodb-releases/linux name: mongodb-versions - mountPath: /tools/db/ name: mongodb-tools - name: nginx-conf mountPath: /etc/nginx/nginx.conf subPath: nginx.conf initContainers: - name: setting-up-rhel-mongodb image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz - -o - /mongodb-ops-manager/mongodb-releases/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz volumeMounts: - name: mongodb-versions mountPath: /mongodb-ops-manager/mongodb-releases/linux - name: setting-up-rhel-mongodb-tools image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel80-x86_64-100.6.0.tgz - -o - /tools/db/mongodb-database-tools-rhel80-x86_64-100.6.0.tgz volumeMounts: - name: mongodb-tools mountPath: /tools/db/ restartPolicy: Always terminationGracePeriodSeconds: 30 volumes: - name: mongodb-versions emptyDir: {} - name: mongodb-tools emptyDir: {} - configMap: name: nginx-conf name: nginx-conf修改示例中突出显示的行以指定要安装的 MongoDB Server 版本。
例如,要将 MongoDB 版本
8.0.0替换为不同的数据库版本,请更新以下区块:- name: setting-up-rhel-mongodb image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz - -o - /mongodb-ops-manager/mongodb-releases/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz更新此区块以修改 MongoDB database Tools 版本:
- name: setting-up-rhel-mongodb-tools image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel80-x86_64-100.6.0.tgz - -o - /tools/db/mongodb-database-tools-rhel80-x86_64-100.6.0.tgz- 要加载多个版本,请附加
curl命令 到您希望 Nginx 提供服务的每个版本的相应 initContainer。
例如,要配置 Nginx 来提供 MongoDB
8.0.0:- name: setting-up-rhel-mongodb image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz - -o - /mongodb-ops-manager/mongodb-releases/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz
- 要加载多个版本,请附加
以
.yaml文件扩展名保存此文件。通过对您创建的 Nginx 资源文件调用以下
kubectl命令来部署 Nginx:kubectl apply -f <nginix>.yaml
将以下示例 Nginx 资源配置粘贴到文本编辑器中:
apiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - image: nginx:1.14.2 imagePullPolicy: IfNotPresent name: nginx ports: - containerPort: 80 volumeMounts: - mountPath: /mongodb-ops-manager/mongodb-releases/linux name: mongodb-versions - mountPath: /tools/db/ name: mongodb-tools - name: nginx-conf mountPath: /etc/nginx/nginx.conf subPath: nginx.conf initContainers: - name: setting-up-rhel-mongodb image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel<version>-8.0.0.tgz - -o - /mongodb-ops-manager/mongodb-releases/linux/mongodb-linux-x86_64-rhel<version>-8.0.0.tgz volumeMounts: - name: mongodb-versions mountPath: /mongodb-ops-manager/mongodb-releases/linux - name: setting-up-rhel-mongodb-tools image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel<version>-x86_64-100.1.0.tgz - -o - /tools/db/mongodb-database-tools-rhel<version>-x86_64-100.1.0.tgz volumeMounts: - name: mongodb-tools mountPath: /tools/db/ restartPolicy: Always terminationGracePeriodSeconds: 30 volumes: - name: mongodb-versions emptyDir: {} - name: mongodb-tools emptyDir: {} - configMap: name: nginx-conf name: nginx-conf修改示例中突出显示的行以指定要安装的 MongoDB Server 版本。
例如,要将 MongoDB 版本
8.0.0替换为不同的数据库版本,请更新以下区块:- name: setting-up-rhel-mongodb image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel<version>-8.0.0.tgz - -o - /mongodb-ops-manager/mongodb-releases/linux/mongodb-linux-x86_64-rhel<version>-8.0.0.tgz更新此区块以修改 MongoDB database Tools 版本:
- name: setting-up-rhel-mongodb-tools image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel<version>-x86_64-100.1.0.tgz - -o - /tools/db/mongodb-database-tools-rhel<version>-x86_64-100.1.0.tgz要加载多个版本,请将
curl命令附加到您希望 Nginx 提供提供服务的每个版本的相应 initContainer 中。例如,要配置 Nginx 来提供 MongoDB
8.0.0:- name: setting-up-rhel-mongodb image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz - -o - /mongodb-ops-manager/mongodb-releases/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz以
.yaml文件扩展名保存此文件。通过对您创建的 Nginx 资源文件调用以下
oc命令来部署 Nginx:oc apply -f <nginix>.yaml
创建 Kubernetes 服务,使 Nginx 可从集群中的其他 Pod 访问。
本教程中的服务通过端口80将 Nginx 暴露给来自 Kubernetes 集群中其他节点的流量。 这允许您使用 Kubernetes 操作符部署的 MongoDB database 资源 pods 从 Nginx 下载安装存档。
运行以下命令,为 Nginx 部署创建服务:
将以下示例服务粘贴到文本编辑器中:
apiVersion: v1kind: Servicemetadata: name: nginx-svc labels: app: nginxspec: ports: - port: 80 protocol: TCP selector: app: nginx以
.yaml文件扩展名保存此文件。通过对创建的服务文件调用以下
kubectl命令来创建服务:kubectl apply -f <nginix-service>.yaml
复制并更新此 Ops Manager 资源的突出显示字段。
突出显示的部分使用以下 Ops Manager 配置设置:
automation.versions.source: remote以spec.configuration远程模式。automation.versions.download.baseUrl在spec.configuration中提供为 MongoDB 安装存档提供服务的 HTTP 资源的基本 URL。更新此行,将
<namespace>替换为您使用 Kubernetes 操作符将资源部署到的命名空间。automation.versions.download.baseUrl.allowOnlyAvailableBuilds: "false"spec.configuration中,以帮助确保企业版构建没有问题。
apiVersion: mongodb.com/v1kind: MongoDBOpsManagermetadata: name: ops-manager-localmodespec: replicas: 1 version: "8.0.0" adminCredentials: ops-manager-admin-secret configuration: # this enables remote mode in Ops Manager automation.versions.source: remote automation.versions.download.baseUrl: "http://nginx-svc.<namespace>.svc.cluster.local:8080" automation.versions.download.baseUrl.allowOnlyAvailableBuilds: "false"
backup: enabled: false
applicationDatabase: members: 3将复制的示例部分粘贴到现有的 Ops Manager 资源中。
打开首选文本编辑器,将对象规范粘贴到资源文件中的相应位置。
追踪你的 Ops Manager 实例的状态。
要检查 Ops Manager 资源的状态,请调用以下命令:
kubectl get om -o yaml -w有关资源部署状态的信息,请参阅排除 Kubernetes 操作符故障。
Ops Manager 资源完成Pending阶段后,该命令将返回类似于以下内容的输出:
status: applicationDatabase: lastTransition: "2020-05-15T16:20:22Z" members: 3 phase: Running type: ReplicaSet version: "8.0.0-ubi8" backup: phase: "" opsManager: lastTransition: "2020-05-15T16:20:26Z" phase: Running replicas: 1 url: http://ops-manager-localmode-svc.mongodb.svc.cluster.local:8080 version: "8.0.0"复制status.opsManager.url字段的值,该字段说明资源的连接URL 。 您可以在创建 ConfigMap 时使用此值 在此过程的稍后部分中。
部署MongoDB database资源。
如果尚未完成,请完成以下先决条件:
在部署 Ops Manager 的同一命名空间中部署MongoDB database 资源。确保您:
将资源的
spec.opsManager.configMapRef.name与 ConfigMap 的metadata.name进行匹配。将资源的
spec.credentials与您创建的包含 Ops Manager 编程 API 密钥对的密钥名称进行匹配。
在使用MongoDB Agent Operator 创建的MongoDB数据库资源容器中运行的 MongoDB Kubernetes通过 Nginx 从MongoDB Ops Manager下载安装存档,而不是从互联网下载。