AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

レプリカセットの配置

注意

このページのMongoDB Ops Managerが表示されている場所では、 Cloud Managerを置き換えることができます。

重要

  • Kubernetes演算子を使用して、MongoDB Cloud ManagerMongoDB Ops Managerおよび バージョン6.0 .x 以降で リソースを配置できます。

  • Atlas 演算子を使用して、MongoDB リソースを Atlas に配置できます。

レプリカセットは、同じデータセットを保持する MongoDB 配置のグループです。 レプリカセットは冗長性と高可用性を提供し、すべての配置環境の基盤となります。

レプリカセットの詳細については、MongoDB マニュアルの 「レプリケーションの概要」を参照してください。

MongoDB Ops Managerが管理する新しいレプリカセットを配置するには、次の手順を使用します。 配置後は、 MongoDB Ops Managerを使用して、ノードの追加、削除、再構成などの操作を含むレプリカセットを管理します。

Kubernetes 演算子 経由でレプリカセットを配置する場合は、TLS 証明書を使用して接続を暗号化するかどうかを選択する必要があります。

TLS-Encrypted接続の次の手順:

  • レプリカセット内の MongoDB ホスト間でTLS暗号化接続を確立します。

  • クライアント アプリケーションと MongoDB 配置間でTLS暗号化接続を確立します。

  • TLS暗号化の有効な証明書が必要です。

Non-Encrypted Connectionsの次の手順:

  • レプリカセット内の MongoDB ホスト間の接続を暗号化しません。

  • クライアント アプリケーションと MongoDB 配置間の接続を暗号化しません。

  • TLS暗号化接続を使用した配置よりもセットアップ要件が少なくなります。

注意

Kubernetes クラスターでは MongoDB のスタンドアロン インスタンスを保護することはできません。

シャーディングされたクラスターのTLS暗号化を設定するには、「 シャーディングされたクラスターの配置 」を参照してください

TLSを使用してレプリカセット接続を暗号化するかどうかに応じて、適切なタブを選択します。

オブジェクトを使用してレプリカセットを配置するには、以下を行う必要があります。

注意

Kubernetes の単一クラスター配置でシークレットが保存されないようにするには、 すべてのシークレットシークレットストレージツールに移行 します。複数のKubernetesクラスターでの配置では、HashiCorp Vault などのシークレットストレージツールへのシークレットの保存はサポートされていません。

  • 次のコンポーネントごとに 1 つのTLS証明書を生成します。

    • レプリカセット。 レプリカセットのノードをホストする各 Kubernetes ポッドのSANを証明書に追加することを確認します。

      TLS証明書では、各ポッドのSANは次の形式を使用する必要があります。

      <pod-name>.<metadata.name>-svc.<namespace>.svc.cluster.local

      重要

      If you're using an ACME based service provider such as Let's Encrypt to issue TLS certificates, the provider might prohibit you from adding the Pod's default FQDNs (*.svc.cluster.local) to SANs in the certificate.

      ACMEベースの証明書を使用するには、レプリカセット リソースの証明書を構成する必要があります。 詳細については、手順の 「 ACMEベースのTLS証明書」 に関するステップを参照してください

    • プロジェクトの MongoDB Agent。 MongoDB Agent 証明書については、次の要件を満たしていることを確認してください。

      • TLS証明書のコモン ネームが空ではない。

      • TLS証明書内の組織と組織単位の組み合わせは、レプリカセット ノードのTLS証明書内の組織と組織単位とは異なります。

  • You must have the CA certificate file and name it ca-pem.

  • TLS証明書の署名に使用したキーが必要です。

重要

The Kubernetes Operator uses kubernetes.io/tls secrets to store TLS certificates and private keys for Ops Manager and MongoDB resources. Starting in Kubernetes Operator version 1.17.0, the Kubernetes Operator doesn't support concatenated PEM files stored as Opaque secrets.

オブジェクトを使用してレプリカセットを配置するには、以下を行う必要があります。

注意

Kubernetes の単一クラスター配置でシークレットが保存されないようにするには、 すべてのシークレットシークレットストレージツールに移行 します。複数のKubernetesクラスターでの配置では、HashiCorp Vault などのシークレットストレージツールへのシークレットの保存はサポートされていません。

1

まだ作成していない場合は、次のコマンドを実行して、作成した名前空間ですべてのkubectlコマンドを実行します

注意

MongoDB Ops Manager リソースを複数の Kubernetes クラスター MongoDB 配置に配置している場合、次の手順に従います。

  • context を演算子クラスターの名前に設定します(kubectl config set context "$MDB_CENTRAL_CLUSTER_FULL_NAME" など)。

  • MongoDB のマルチ配置に使用したのと同じスコープ(例: kubectl config --namespace "mongodb"--namespaceを設定します。

kubectl config set-context $(kubectl config current-context) --namespace=<metadata.namespace>
2

このkubectl コマンドを実行して新しい シークレット を作成します レプリカセットの証明書を保存する

kubectl create secret tls <prefix>-<metadata.name>-cert \
--cert=<replica-set-tls-cert> \
--key=<replica-set-tls-key>

注意

シークレットの前に<prefix>-<metadata.name>を付ける必要があります。

For example, if you call your deployment my-deployment and you set the prefix to mdb, you must name the TLS secret for the client TLS communications mdb-my-deployment-cert. Also, you must name the TLS secret for internal cluster authentication (if enabled) mdb-my-deployment-clusterfile.

HashiCorp Vaultシークレットストレージツール として使用している場合は、代わりに Vault シークレットを作成 できます。

シークレット ストレージのオプションの詳細については、「シークレット ストレージの構成 」を参照してください。

3

次の kubectl コマンドを実行して、エージェントの TLS 証明書を保存する新しいシークレットを作成します。

kubectl create secret tls <prefix>-<metadata.name>-agent-certs \
--cert=<agent-tls-cert> \
--key=<agent-tls-key>

HashiCorp Vaultシークレットストレージツール として使用している場合は、代わりに Vault シークレットを作成 できます。

4

このkubectlコマンドを実行してCAをレプリカセットにリンクし、 CA証明書ファイルを指定します。

重要

Kubernetes Operator では、ConfigMap でMongoDBリソースの証明書がca-pemという名前を持つ必要があります。

kubectl create configmap custom-ca --from-file=ca-pem=<your-custom-ca-file>
5

このYAMLファイルの設定を、必要なレプリカセット構成に合わせて変更します。

1---
2apiVersion: mongodb.com/v1
3kind: MongoDB
4metadata:
5 name: <my-replica-set>
6spec:
7 members: 3
8 version: "8.0.0"
9 opsManager:
10 configMapRef:
11 # Must match metadata.name in ConfigMap file
12 name: <configMap.metadata.name>
13 credentials: <mycredentials>
14 type: ReplicaSet
15 persistent: true
16...
16 security:
17 tls:
18 ca: <custom-ca>
19 certsSecretPrefix: <prefix>
20...
6

任意のテキストエディタを開き、オブジェクト仕様を新しいテキストファイルに貼り付けます。

7
キー
タイプ
説明

string

この Kubernetes レプリカセット オブジェクト のラベル 。

リソース名は 44 文字以下にする必要があります。

metadata.name詳しくは、名前に関する とKubernetes のドキュメントを参照してください。

myproject

integer

Number of members of the replica set.

3

string

このレプリカセットが実行する MongoDB のバージョン。

形式は、 MongoDB Community Editionでは X.Y.Z、Enterprise エディションでは X.Y.Z-ent です。

重要:互換性のあるMongoDB Serverバージョンを選択していることを確認してください。 互換性のあるバージョンは、 MongoDBデータベースリソースが使用する基本イメージによって異なります。

MongoDB のバージョン管理の詳細については、MongoDB マニュアルの「 MongoDBのバージョン管理 」を参照してください。

8.0.0

spec
.opsManager
.configMapRef
.name

string

Name of the ConfigMap with the Ops Manager connection configuration. The spec.cloudManager.configMapRef.name setting is an alias for this setting and can be used in its place.

この値は、作成するリソースと同じ名前空間に存在する必要があります。

重要: Kubernetes Operator は ConfigMap への変更を追跡し、MongoDB リソースの状態を調整します。

<myconfigmap>

string

Name of the secret you created as Ops Manager API authentication credentials for the Kubernetes Operator to communicate with Ops Manager.

認証情報を保持するMongoDB Ops Manager Kubernetes Secretオブジェクトは、作成するリソースと同じ名前空間に存在する必要があります。

重要: Kubernetes Operator は、シークレットへの変更を追跡し、MongoDB リソースの状態を調整します。

<mycredentials>

string

作成するMongoDBリソースのタイプ。

ReplicaSet

string

任意。

Flag indicating if this MongoDB resource should use Persistent Volumes for storage. Persistent volumes are not deleted when the MongoDB resource is stopped or restarted.

この値がtrueの場合、 spec.podSpec.persistence.singleはデフォルト値の16Giに設定されます。

永続的なボリュームクレーム を変更するには 構成では、配置の要件を満たすように次のコレクションを構成します。

WARNING: Grant your containers permission to write to your Persistent Volume. The Kubernetes Operator sets fsGroup = 2000, runAsUser = 2000, and runAsNonRoot = true in securityContext. Kubernetes Operator sets fsgroup equal to runAsUser to make the volume writable for a user that runs the main process in the container. To learn more, see Configure a Security Context for a Pod or Container and the related discussion in the Kubernetes documentation. If redeploying the resource doesn't fix issues with your Persistent Volume, contact MongoDB Support.

If you do not use Persistent Volumes, the Disk Usage and Disk IOPS charts cannot be displayed in either the Processes tab on the Deployment page or in the Metrics page when reviewing the data for this deployment.

true

8

配置でTLSを有効にするには、Kubernetes オブジェクトで次の設定を構成します。

キー
タイプ
必要性
説明

spec.security
.tls.ca

string

必須

ConfigMap を追加する 配置の TLS 証明書に署名するために使用したカスタム CA を保存する の名前。

<custom-ca>

spec.security
.certsSecretPrefix

string

必須

MongoDB 配置のTLS証明書を含むシークレット名の<prefix>を追加します。

For example, if you call your deployment my-deployment and you set the prefix to mdb, you must name the TLS secret for the client TLS communications mdb-my-deployment-cert. Also, you must name the TLS secret for internal cluster authentication (if enabled) mdb-my-deployment-clusterfile.

devDb

9

If you're using an ACME based service provider such as Let's Encrypt to issue TLS certificates, the provider might prohibit you from adding the Pod's default FQDNs (*.svc.cluster.local) to SANs in the certificate.

ポッドのFQDNを含まない証明書を設定するには、次の手順に従います。

  1. 外部ドメインの証明書を発行します。詳細については、let の暗号化のドキュメント、またはプロバイダーのドキュメントを参照してください。

  2. 証明書にレプリカセットに配置するすべてのホスト名が含まれていることを確認します。 あるいは、 *.<externalDomain>の ワイルドカード 証明書を発行することもできます。

  3. レプリカセットの配置で外部ドメインのみを含む証明書を使用するには、レプリカセットで使用されるデフォルトのホスト名を変更する必要があります。

    • If you prefer to configure the hostname while creating your Kubernetes cluster, change the default domain from cluster.local to the external domain when creating or recreating your Kubernetes cluster. Then, set this domain in your MongoDB resource by using the spec.clusterDomain setting.

    • それ以外の場合は、Kubernetes オブジェクトで構成されている次の設定を使用して MongoDB 配置を作成します。

キー
タイプ
必要性
説明

spec.externalAccess
.externalDomain

string

必須

レプリカセットの配置を外部で公開するために使用される外部ドメイン。

By default, each replica set member uses the Kubernetes Pod's FQDN (*.svc.cluster.local) as the default hostname. However, if you add an external domain to this setting, the replica set uses a hostname that is a subdomain of the specified domain instead. This hostname uses the following format:

<replica-set-name>-<pod-idx>.<externalDomain>

以下に例を挙げます。

replica-set-1.example.com

After you deploy the replica set with this setting, the Kubernetes Operator uses the hostname with the external domain to override the processes[n].hostname field in the Ops Manager automation configuration. Then, the MongoDB Agent uses this hostname to connect to mongod.

レプリカセットに接続するための他のホスト名を指定するには、 spec.connectivity.replicaSetHorizons設定を使用できます。 ただし、次の接続では、外部ドメインを含むホスト名は引き続き使用されます。

WARNING: Specifying this field changes how Ops Manager registers mongod processes. You can't change the value of this field or any processes[n].hostname fields in the Ops Manager automation configuration for a running replica set deployment.

spec.externalAccess
.externalService.spec

コレクション

任意

ServiceSpec の構成。

spec.externalAccess 設定を設定すると、 Kubernetes Operator は デフォルト値 の外部ロードバランサーサービスを自動的に作成します。ニーズに応じて、特定の値を上書きしたり、新しい値を追加したりできます。例、NodePort サービスを作成し、ロードバランサーが必要ない場合は、 Kubernetes仕様でオーバーライドを構成する必要があります。

externalAccess:
externalService:
annotations:
# cloud-specific annotations for the service
spec:
type: NodePort # default is LoadBalancer
# you can specify other spec overrides if necessary

Kubernetes仕様の詳細については、Kubernetesドキュメントの ServiceSpec を参照してください。

spec.externalAccess
.externalService.annotations

コレクション

任意

配置内のすべてのクラスターにクラウドプロバイダー固有の構成設定を追加できるキーと値のペア。詳しくは、 「 Kubernetesクラウドプロバイダー 」の注釈とドキュメントを参照してください。

プレースホルダー値を指定して注釈をカスタマイズできます。 詳しくは、 spec.externalAccess.externalService.annotationsを参照してください。

10

また、次の任意設定のいずれかを オブジェクト に追加できます。 レプリカセット 配置の仕様ファイル。

警告

You must set spec.clusterDomain if your Kubernetes cluster has a default domain other than the default cluster.local. If you neither use the default nor set the spec.clusterDomain option, the Kubernetes Operator might not function as expected.

11
12

任意のディレクトリで、次の Kubernetes コマンドを呼び出してレプリカセットを作成します。

kubectl apply -f <replica-set-conf>.yaml
13

MongoDBリソースのステータスを確認するには、次のコマンドを使用します。

kubectl get mdb <resource-name> -o yaml -w

-w (監視)フラグが設定されている場合、構成が変更されると、ステータスフェーズがRunning状態に達するまで出力が直ちに更新されます。 リソース配置ステータスの詳細については、 「 Kubernetes 演算子のトラブルシューティング 」を参照してください。

TLSを使用してデータベース リソースを暗号化すると、以下を保護できます。

次の手順で、 TLS証明書を定期的に更新します。

1

まだ作成していない場合は、次のコマンドを実行して、作成した名前空間ですべてのkubectlコマンドを実行します

注意

MongoDB Ops Manager リソースを複数の Kubernetes クラスター MongoDB 配置に配置している場合、次の手順に従います。

  • context を演算子クラスターの名前に設定します(kubectl config set context "$MDB_CENTRAL_CLUSTER_FULL_NAME" など)。

  • MongoDB のマルチ配置に使用したのと同じスコープ(例: kubectl config --namespace "mongodb"--namespaceを設定します。

kubectl config set-context $(kubectl config current-context) --namespace=<metadata.namespace>
2

既存の シークレット を更新するには、このkubectl コマンドを実行します レプリカセットの証明書を保存する

kubectl create secret tls <prefix>-<metadata.name>-cert \
--cert=<replica-set-tls-cert> \
--key=<replica-set-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -
1

まだ作成していない場合は、次のコマンドを実行して、作成した名前空間ですべてのkubectlコマンドを実行します

注意

MongoDB Ops Manager リソースを複数の Kubernetes クラスター MongoDB 配置に配置している場合、次の手順に従います。

  • context を演算子クラスターの名前に設定します(kubectl config set context "$MDB_CENTRAL_CLUSTER_FULL_NAME" など)。

  • MongoDB のマルチ配置に使用したのと同じスコープ(例: kubectl config --namespace "mongodb"--namespaceを設定します。

kubectl config set-context $(kubectl config current-context) --namespace=<metadata.namespace>
2

このYAMLファイルの設定を、必要なレプリカセット構成に合わせて変更します。

1---
2apiVersion: mongodb.com/v1
3kind: MongoDB
4metadata:
5 name: <my-replica-set>
6spec:
7 members: 3
8 version: "8.0.0"
9 opsManager:
10 configMapRef:
11 # Must match metadata.name in ConfigMap file
12 name: <configMap.metadata.name>
13 credentials: <mycredentials>
14 type: ReplicaSet
15 persistent: true
16...
3

任意のテキストエディタを開き、オブジェクト仕様を新しいテキストファイルに貼り付けます。

4
キー
タイプ
説明

string

この Kubernetes レプリカセット オブジェクト のラベル 。

リソース名は 44 文字以下にする必要があります。

metadata.name詳しくは、名前に関する とKubernetes のドキュメントを参照してください。

myproject

integer

Number of members of the replica set.

3

string

このレプリカセットが実行する MongoDB のバージョン。

形式は、 MongoDB Community Editionでは X.Y.Z、Enterprise エディションでは X.Y.Z-ent です。

重要:互換性のあるMongoDB Serverバージョンを選択していることを確認してください。 互換性のあるバージョンは、 MongoDBデータベースリソースが使用する基本イメージによって異なります。

MongoDB のバージョン管理の詳細については、MongoDB マニュアルの「 MongoDBのバージョン管理 」を参照してください。

8.0.0

spec
.opsManager
.configMapRef
.name

string

Name of the ConfigMap with the Ops Manager connection configuration. The spec.cloudManager.configMapRef.name setting is an alias for this setting and can be used in its place.

この値は、作成するリソースと同じ名前空間に存在する必要があります。

重要: Kubernetes Operator は ConfigMap への変更を追跡し、MongoDB リソースの状態を調整します。

<myconfigmap>

string

Name of the secret you created as Ops Manager API authentication credentials for the Kubernetes Operator to communicate with Ops Manager.

認証情報を保持するMongoDB Ops Manager Kubernetes Secretオブジェクトは、作成するリソースと同じ名前空間に存在する必要があります。

重要: Kubernetes Operator は、シークレットへの変更を追跡し、MongoDB リソースの状態を調整します。

<mycredentials>

string

作成するMongoDBリソースのタイプ。

ReplicaSet

string

任意。

Flag indicating if this MongoDB resource should use Persistent Volumes for storage. Persistent volumes are not deleted when the MongoDB resource is stopped or restarted.

この値がtrueの場合、 spec.podSpec.persistence.singleはデフォルト値の16Giに設定されます。

永続的なボリュームクレーム を変更するには 構成では、配置の要件を満たすように次のコレクションを構成します。

WARNING: Grant your containers permission to write to your Persistent Volume. The Kubernetes Operator sets fsGroup = 2000, runAsUser = 2000, and runAsNonRoot = true in securityContext. Kubernetes Operator sets fsgroup equal to runAsUser to make the volume writable for a user that runs the main process in the container. To learn more, see Configure a Security Context for a Pod or Container and the related discussion in the Kubernetes documentation. If redeploying the resource doesn't fix issues with your Persistent Volume, contact MongoDB Support.

If you do not use Persistent Volumes, the Disk Usage and Disk IOPS charts cannot be displayed in either the Processes tab on the Deployment page or in the Metrics page when reviewing the data for this deployment.

true

5

また、次の任意設定のいずれかを オブジェクト に追加できます。 レプリカセット 配置の仕様ファイル。

警告

You must set spec.clusterDomain if your Kubernetes cluster has a default domain other than the default cluster.local. If you neither use the default nor set the spec.clusterDomain option, the Kubernetes Operator might not function as expected.

6
7

任意のディレクトリで、次の Kubernetes コマンドを呼び出してレプリカセットを作成します。

kubectl apply -f <replica-set-conf>.yaml
8

MongoDBリソースのステータスを確認するには、次のコマンドを使用します。

kubectl get mdb <resource-name> -o yaml -w

-w (監視)フラグが設定されている場合、構成が変更されると、ステータスフェーズがRunning状態に達するまで出力が直ちに更新されます。 リソース配置ステータスの詳細については、 「 Kubernetes 演算子のトラブルシューティング 」を参照してください。