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

Kubernetes 演算子のクイック スタート

重要

このセクションは、単一の Kubernetes クラスターの配置のみを対象としています。 MongoDB のマルチ Kubernetes クラスター配置については、概要を参照してください。

The MongoDB Controllers for Kubernetes Operator uses the Kubernetes API and tools to manage MongoDB clusters running within your Kubernetes cluster. Kubernetes Operator works together with Ops Manager. This tutorial demonstrates how to deploy Ops Manager on Kubernetes and then deploy and connect to your first MongoDB replica set with Kubernetes Operator. You can use Kind to quickly set up a cluster. To learn more, see Kind.

Use this tutorial to evaluate Kubernetes Operator. Because Kind runs a single node on your local machine, the deployment that you create here can't survive node loss and isn't sized for production traffic. After you finish, see Next Steps to learn how to move to a production deployment.

このチュートリアルには次のものが必要です。

Docker Desktop で Kind を使用する場合は、Docker Desktop のリソース設定で少なくとも 8 GB のメモリ および 4 個の CPU を割り当ててください。Ops Manager は、アプリケーションに対して最低 5 GB のメモリを必要とします。また、アプリケーションデータベースと Kubernetes 演算子に対しては追加のリソースが必要です。

1
helm repo add mongodb https://mongodb.github.io/helm-charts
2

Helm とともにKubernetes Operator をインストールするには、リポジトリの手順を参照してください。

例

次のコマンドは、任意の --create-namespace オプションを使用して、mongodb名前空間にMongoDB Controls for Kubernetes Operator をインストールします。デフォルトでは 、 Kubernetes Operator は default名前空間を使用します。

helm install kubernetes-operator mongodb/mongodb-kubernetes --namespace mongodb --create-namespace
3

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

kubectl config set-context $(kubectl config current-context) --namespace=mongodb
4

MongoDB Ops Managerの初期アドミンユーザーの認証情報を含むシークレットを作成します。Kubernetes 演算子は、MongoDB Ops Manager リソースを配置する際に、このシークレットを使用して最初のアドミンユーザーを構成します。

プレースホルダーの値を好みの認証情報に置き換えて、次のコマンドを実行します。

kubectl create secret generic ops-manager-admin-secret \
--from-literal=Username="<admin-email>" \
--from-literal=Password="<admin-password>" \
--from-literal=FirstName="<first-name>" \
--from-literal=LastName="<last-name>"

注意

これらの認証情報は安全に保存してください。配置後に MongoDB Ops Manager UI にログインするには、これらの認証情報が必要です。

5
  1. 次のYAMLファイルをops-manager.yamlとしてコピーして保存します。

    apiVersion: mongodb.com/v1
    kind: MongoDBOpsManager
    metadata:
    name: ops-manager
    namespace: mongodb
    spec:
    replicas: 1
    version: "8.0.0"
    adminCredentials: ops-manager-admin-secret
    externalConnectivity:
    type: NodePort
    configuration:
    mms.ignoreInitialUiSetup: "true"
    automation.versions.source: "mongodb"
    mms.fromEmailAddr: admin@example.com
    mms.replyToEmailAddr: admin@example.com
    mms.adminEmailAddr: admin@example.com
    mms.mail.transport: smtp
    mms.mail.hostname: localhost
    mms.mail.port: "25"
    backup:
    enabled: false
    applicationDatabase:
    topology: SingleCluster
    members: 3
    version: "8.0.0"

    詳細については、MongoDB Ops Manager リソース仕様を参照してください。

  2. 次のコマンドを実行します:

    kubectl apply -f ops-manager.yaml
6

Kubernetes 演算子は、まずアプリケーションデータベースのレプリカセットを配置し、次に MongoDB Ops Manager アプリケーションを起動します。このプロセスには数分かかる場合があります。

次のコマンドを実行して、リソースのステータスを追跡します。

kubectl get om -o yaml -w

出力に次のフェーズが表示されるまで待ちます。

status:
applicationDatabase:
phase: Running
opsManager:
phase: Running

両方のコンポーネントが Running に達したら、Ops Manager URL を取得します。

kubectl get om ops-manager -o jsonpath='{.status.opsManager.url}'

この URL を控えておいてください。後の手順で ConfigMap に必要になります。

7

MongoDB Ops Manager UI を使用して ConfigMap と Secret を生成するか、手動で作成することができます。

まず、Ops Manager サービス ポートをローカル マシンに転送して、ブラウザーで UI にアクセスできるようにします。

kubectl port-forward svc/ops-manager-svc-ext 8080:8080

次に、ブラウザで http://localhost:8080 を開き、管理シークレットで作成した認証情報を使用してログインします。

MongoDB Ops Manager UI を使用するには、次の手順で操作します。

  1. [Create New API Keys] または [Use Existing API Keys] をクリックします。

  2. フォームを完成します。詳細については、Kubernetes 演算子の認証情報の作成を参照してください。

  3. [Generate Key and YAML] をクリックします。

または、次の手順で ConfigMap と Secret を手動で作成できます。

8

MongoDB Ops Manager UI から ConfigMap を生成した場合は、生成された config-map.yaml ファイルをコピーして保存します。そうでない場合は、次のファイルを作成して保存します。data.baseUrl を status.opsManager.url からの MongoDB Ops Manager インスタンスの URL に設定します。

例:

apiVersion: v1
kind: ConfigMap
metadata:
name: my-project
namespace: mongodb
data:
baseUrl: http://ops-manager-svc.mongodb.svc.cluster.local:8080
projectName: my-project
orgId: <your-org-id>

<your-org-id> を MongoDB Ops Manager 組織 ID に置き換えます。この値は MongoDB Ops Manager UI URL: http://<ops-manager-url>/v2#/org/<orgId>/projects で確認できます。

詳しくは、パラメーターの説明を参照してください。

9

If you generated the Secret from the Ops Manager UI, copy and save the generated secret.yaml file. Otherwise, create a secret that contains the API keys for your Ops Manager Organization.

例:

apiVersion: v1
kind: Secret
metadata:
name: organization-secret
namespace: mongodb
stringData:
publicKey: <public_key>
privateKey: <private_key>

プログラムによる API キーを作成するには、Kubernetes 演算子の認証情報を作成する を参照してください。

10

次のコマンドを実行します:

kubectl apply -f secret.yaml -f config-map.yaml
11
  1. 次のYAMLファイルをコピーして保存します。

    apiVersion: mongodb.com/v1
    kind: MongoDB
    metadata:
    name: demo-mongodb-cluster-1
    namespace: mongodb
    spec:
    members: 3
    version: 8.0.0
    type: ReplicaSet
    security:
    authentication:
    enabled: true
    modes: ["SCRAM"]
    opsManager:
    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
  2. 次のコマンドを実行します:

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

MongoDB データベースユーザーのパスワードを選択し、シークレットに保存します。このパスワードは、任意の値にできます。次のステップでデータベースユーザーを作成する際に、このシークレットを参照します。

パスワードはクリアテキストとして(stringDataを使用)、または Base64 エンコード値として(dataを使用)保存できます。

クリアテキスト パスワードの場合は、次の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

プレースホルダーを選択したパスワードに置き換えます。詳細については、「 SCRAM 認証を使用したデータベースユーザーの管理」を参照してください。

13
  1. 次の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"
  2. 次のコマンドを実行します:

    kubectl apply -f <database-user-conf>.yaml
14

新しく作成されたユーザーは、 Cloud ManagerまたはMongoDB Ops Managerで表示できます。

  1. プロジェクトのDeploymentビューから、 Securityタブをクリックします。

  2. [ MongoDB Users ] ネストされたタブをクリックします。

15

MongoDB Ops Managerアプリケーションで次の手順を実行します。

  1. 左側のナビゲーションで [ Deployment ] をクリックします。

  2. をクリックします接続する配置の 。

  3. [Connect to this instance] をクリックします。

  4. 配置に接続するには、ターミナルで接続コマンドを実行します。

作成した配置は、単一のKindノード上で実行され、デフォルトのリソース設定を使用します。この評価用配置から本番用配置へ移行するには:

  1. 本番環境の配置を計画するには、アーキテクチャの選択、バージョンの互換性の確認、Kubernetes 演算子の配置範囲の設定を行います。

  2. 複数のノードとボリューム展開をサポートする storageClass を持つ本番用 Kubernetes クラスターに Kubernetes 演算子をインストールします。

  3. ストレージ、永続性、アベイラビリティーゾーン、リソース制限について、本番環境のベストプラクティスを適用します。

  4. 配置のセキュリティを確保するには、TLS、認証、保管時の暗号化を使用します。

  5. Kubernetes クラスター全体の損失から復旧する必要がある場合は、複数の Kubernetes クラスターに配置します。

このページを評価