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 。
先决条件
本教程要求:
正在运行的 MongoDB Cloud Manager 集群。
正在运行的 Kubernetes 集群。
Kubernetes 节点在支持的硬件架构上运行。
步骤
将MongoDB Helm Charts for Kubernetes存储库添加到 Helm。
helm repo add mongodb https://mongodb.github.io/helm-charts
安装 MongoDB Enterprise Kubernetes Operator
要安装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
配置 Kubernetes Operator
单击 Create New API Keys 或 Use Existing API Keys。
填写表格。 要了解更多信息,请参阅对 Cloud Manager 的编程访问。
单击 Generate Key and YAML(连接)。
复制并保存 ConfigMap。
复制并保存生成的 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
要了解更多信息,请参阅参数说明。
部署MongoDB副本集资源。
复制并保存以下 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 运行以下命令:
kubectl apply -f <replica-set-conf>.yaml
使用数据库用户密码创建密钥
您可以选择使用明文密码或 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
创建数据库用户。
复制并保存以下 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" 运行以下命令:
kubectl apply -f <database-user-conf>.yaml
连接到MongoDB副本集。
在 Cloud Manager 应用程序中执行以下步骤:
单击左侧导航栏中的 Deployment。
单击要连接到的部署的 。
单击 Connect to this instance(连接)。
在终端中运行连接命令,以连接到部署。