重要
このセクションは、単一の Kubernetes クラスターの配置のみを対象としています。 マルチKubernetes クラスターの MongoDB 配置については、 「マルチKubernetes クラスター クイック スタート」 を参照してください。
MongoDB Enterprise Kubernetes Operator uses the Kubernetes API and tools to manage MongoDB clusters. Kubernetes Operator works together with MongoDB Cloud Manager or Ops Manager. This tutorial demonstrates how to deploy and connect to your first replica set in MongoDB Cloud Manager with Kubernetes Operator. You can use Kind to quickly set up a cluster. To learn more, see Kind.
前提条件
このチュートリアルには次のものが必要です。
実行中の MongoDB Cloud Manager クラスター。
実行中の Kubernetes クラスター。
手順
MongoDB Helm Charts for Kubernetesリポジトリを Helm に追加します。
helm repo add mongodb https://mongodb.github.io/helm-charts
MongoDB Enterprise Kubernetes Operatorのインストール
Helm Chart を使用してKubernetes Operator をインストールするには、リポジトリの手順を参照してください。
例
次のコマンドは、任意の--create-namespace
オプションを使用して、 mongodb
名前空間に MongoDB Enterprise Kubernetes Operator をインストールします。 デフォルトでは、Kubernetes Operator はdefault
名前空間を使用します。
helm install enterprise-operator mongodb/enterprise-operator --namespace mongodb --create-namespace
Kubernetes 演算子の構成
[ 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
詳しくは、パラメーターの説明を参照してください。
レプリカセットリソースます。
次の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 authentication roles: - db: "admin" name: "clusterAdmin" - db: "admin" name: "userAdminAnyDatabase" - db: "admin" name: "readWrite" 次のコマンドを実行します:
kubectl apply -f <database-user-conf>.yaml
レプリカセットに接続します。
Cloud Managerアプリケーションで次の手順を実行します。
左側のナビゲーションで [ Deployment ] をクリックします。
をクリックします接続する配置の 。
[Connect to this instance] をクリックします。
配置に接続するには、ターミナルで接続コマンドを実行します。