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 に配置できます。

sharded cluster provide horizontal scaling for large data sets and enable high throughput operations by distributing the data set across a group of servers.

シャーディングの詳細については、MongoDB マニュアルの「 シャーディングの概要 」を参照してください。

MongoDB Ops Managerが管理する新しいシャーディングされたクラスターを配置するには、この手順を使用します。 後で、 MongoDB Ops Managerを使用してシャードを追加し、クラスターでその他のメンテナンス操作を実行できます。

Kubernetes ネットワーク変換のため、Kubernetes 外の監視エージェントは Kubernetes 内の MongoDB インスタンスを監視できません。 このため、同じプロジェクト内で k 8と非 k 8の配置はサポートされていません。 別々のプロジェクトを使用します。

Kubernetes 演算子 経由で クラスター を配置する場合は、TLS 証明書を使用して接続を暗号化するかどうかを選択する必要があります。

TLS-Encrypted接続の次の手順:

  • クラスター シャード間でTLS暗号化接続を確立します。

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

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

Non-Encrypted Connectionsの次の手順:

  • クラスター シャード間の接続を暗号化しません。

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

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

注意

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

レプリカセットのTLS暗号化を設定するには、「 レプリカセットの配置 」を参照してください

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

オブジェクト を使用してシャーディングされたクラスターを配置するには に設定されている場合は、以下を行う必要があります。

注意

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

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

    • シャーディングされたクラスター内の各シャード。 シャード ノードをホストする各 Kubernetes ポッドのSANを証明書に追加することを確認します。

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

      <pod-name>.<metadata.name>-sh.<namespace>.svc.cluster.local
    • コンフィギュレーションサーバー。 コンフィギュレーションサーバーをホストする各 Kubernetes ポッドのSANを証明書に追加することを確認します。

      TLS証明書では、各コンフィギュレーションサーバー ポッドのSANは次の形式を使用する必要があります。

      <pod-name>.<metadata.name>-cs.<namespace>.svc.cluster.local
    • Your mongos instances. Ensure that you add SANs for each Kubernetes pod that hosts a mongos to the certificate.

      In your TLS certificates, the SAN for each mongos pod must use this format:

      <pod-name>.<metadata.name>-svc.<namespace>.svc.cluster.local
    • プロジェクトの MongoDB Agent。 MongoDB Agent 証明書については、次の要件を満たしていることを確認してください。

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

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

  • CA証明書と、 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 -n mongodb create secret tls <prefix>-<metadata.name>-0-cert \
--cert=<shard-0-tls-cert> \
--key=<shard-0-tls-key>
kubectl -n mongodb create secret tls <prefix>-<metadata.name>-1-cert \
--cert=<shard-1-tls-cert> \
--key=<shard-1-tls-key>

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

3

次のkubectlコマンドを実行して、シャーディングされたクラスター コンフィギュレーションサーバーの証明書を保存する新しいシークレットを作成します。

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-config-cert \
--cert=<config-tls-cert> \
--key=<config-tls-key>

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

4

Run this kubectl command to create a new secret that stores the sharded cluster mongos certificate:

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-mongos-cert \
--cert=<mongos-tls-cert> \
--key=<mongos-tls-key>

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

5

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

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

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

6

Run this kubectl command to link your CA to your sharded cluster and specify the CA certificate file that you must always name ca-pem for the MongoDB resource:

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

このYAMLファイルの設定を、シャーディングされたクラスターの構成に合わせて変更します。

必要なシャーディングされたクラスターの構成に合わせて設定を変更します。

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

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

9
キー
タイプ
説明

string

このKubernetesシャーディングされたクラスターオブジェクトのラベル。

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

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

myproject

integer

配置するシャードの数。

2

integer

シャードあたりの シャード ノードの数。

3

integer

配置するシャード ルーターの数。

2

integer

コンフィギュレーションサーバー レプリカセットのノードの数。

3

string

このシャーディングされたクラスターが実行する MongoDB のバージョン。

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

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

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

最良の結果を得るには、利用 可能な最新のエンタープライズ MongoDB バージョン を使用してください MongoDB Ops Manager のバージョンと 互換性 のある 。

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 リソースの状態を調整します。

<myproject>

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リソースのタイプ。

ShardedCluster

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の場合、次の値はデフォルト値の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

10

配置で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

11

オブジェクト また、シャーディングされたクラスター配置のオブジェクト仕様ファイルに、次のいずれかのオプション設定を追加することもできます。

警告

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.

For config server

シャード ルーターの場合

シャード ノードの場合

12
13

次の Kubernetes コマンドを呼び出して、シャーディングされたクラスターを作成します。

kubectl apply -f <sharded-cluster-conf>.yaml

このコマンドを実行した後、ログを確認します。 作成が成功した場合は、次のようなメッセージが表示されます。

2018-06-26T10:30:30.346Z INFO operator/shardedclusterkube.go:52 Created! {"sharded cluster": "my-sharded-cluster"}
14

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 -n mongodb create secret tls <prefix>-<metadata.name>-0-cert \
--cert=<shard-0-tls-cert> \
--key=<shard-0-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -
kubectl -n mongodb create secret tls <prefix>-<metadata.name>-1-cert \
--cert=<shard-1-tls-cert> \
--key=<shard-1-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -
3

シャーディングされたクラスターコンフィギュレーションサーバーの証明書を保存する既存のシークレットを更新するには、次の kubectl コマンドを実行します。

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-config-cert \
--cert=<config-tls-cert> \
--key=<config-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -
4

Run this kubectl command to renew an existing secret that stores the sharded cluster mongos certificates:

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-mongos-cert \
--cert=<mongos-tls-cert> \
--key=<mongos-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ファイルの設定を、シャーディングされたクラスターの構成に合わせて変更します。

これは、必要な構成に合わせて変更できるYAMLファイルです。 必要なシャーディングされたクラスターの構成に合わせて設定を変更します。

1---
2apiVersion: mongodb.com/v1
3kind: MongoDB
4metadata:
5 name: <my-sharded-cluster>
6spec:
7 shardCount: 2
8 mongodsPerShardCount: 3
9 mongosCount: 2
10 configServerCount: 3
11 version: "8.0.0"
12 opsManager:
13 configMapRef:
14 name: <configMap.metadata.name>
15 # Must match metadata.name in ConfigMap file
16 credentials: <mycredentials>
17 type: ShardedCluster
18 persistent: true
19...
3

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

4
キー
タイプ
説明

string

このKubernetesシャーディングされたクラスターオブジェクトのラベル。

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

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

myproject

integer

配置するシャードの数。

2

integer

シャードあたりの シャード ノードの数。

3

integer

配置するシャード ルーターの数。

2

integer

コンフィギュレーションサーバー レプリカセットのノードの数。

3

string

このシャーディングされたクラスターが実行する MongoDB のバージョン。

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

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

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

最良の結果を得るには、利用 可能な最新のエンタープライズ MongoDB バージョン を使用してください MongoDB Ops Manager のバージョンと 互換性 のある 。

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 リソースの状態を調整します。

<myproject>

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リソースのタイプ。

ShardedCluster

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の場合、次の値はデフォルト値の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.

For config server

シャード ルーターの場合

シャード ノードの場合

6
7

次の Kubernetes コマンドを呼び出して、シャーディングされたクラスターを作成します。

kubectl apply -f <sharded-cluster-conf>.yaml

このコマンドを実行した後、ログを確認します。 作成が成功した場合は、次のようなメッセージが表示されます。

2018-06-26T10:30:30.346Z INFO operator/shardedclusterkube.go:52 Created! {"sharded cluster": "my-sharded-cluster"}
8

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

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

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