重要
このセクションは、単一の Kubernetes クラスターの配置のみを対象としています。 MongoDB のマルチ Kubernetes クラスター配置については、概要を参照してください。
MongoDB Controls for Kubernetes Operator は、 Kubernetes APIとツールを使用してMongoDBクラスターを管理します。Kubernetes Operator は、 MongoDB Cloud ManagerまたはMongoDB Ops Managerと連携します。 このチュートリアルでは、 Kubernetes Operator を使用してOpenShiftからCloud ManagerまたはMongoDB Ops Manager の最初のレプリカセットを配置して接続する方法を説明します。
前提条件
このチュートリアルには次のものが必要です。
- 実行中のCloud ManagerまたはMongoDB Ops Managerクラスター。
手順
MongoDB Kubernetes演算子用コントローラーリポジトリをクローンし、現在のリリースのタグをチェックアウトします。
git clone https://github.com/mongodb/mongodb-kubernetes.gitcd mongodb-kubernetesgit checkout 1.15.0名前空間 を作成する (Kubernetes 配置用)。
デフォルトでは 、 Kubernetes演算子は mongodb名前空間を使用します。インストールを簡素化するために、次の kubernetes コマンドを使用して mongodb というラベルの付いた名前空間を作成することを検討してください。
kubectl create namespace mongodbKubernetes Operator 用のMongoDBドライバーのインストール
次の OC コマンドを呼び出して、 MongoDB配置用の CustomResourceDefinitions をインストールします。
oc apply -f crds.yamlKubernetes Operator YAMLファイル用のMongoDBコントロール の
ServiceAccount定義に<openshift-pull-secret>を追加します。apiVersion: v1kind: ServiceAccountmetadata: name: enterprise-operator namespace: mongodb imagePullSecrets: - name: <openshift-pull-secret> apiVersion: v1kind: ServiceAccountmetadata: name: mongodb-kubernetes-appdb namespace: mongodb imagePullSecrets: - name: <openshift-pull-secret> apiVersion: v1kind: ServiceAccountmetadata: name: mongodb-kubernetes-database-pods namespace: mongodb imagePullSecrets: - name: <openshift-pull-secret>Kubernetes Operator をインストールするには、次の OC コマンドを呼び出します。
oc apply -f mongodb-kubernetes-openshift.yaml
認証情報を作成し、シークレットとして保存します。
次のコマンドを実行します:
注意
次のパラメーターに公開キーの値と秘密キーの値を指定します。 詳細については、「 Kubernetes Operator の認証情報の作成 」を参照してください。
kubectl -n mongodb \ create secret generic ops-manager-admin-key \ --from-literal="publicKey=<publicKey>" \ --from-literal="privateKey=<privateKey>"以下のコマンドを呼び出して ConfigMap を作成します。
cat <<EOF | kubectl apply -f -apiVersion: v1kind: ConfigMapmetadata: name: my-project namespace: mongodbdata: projectName: myProjectName # this is an optional parameter; when omitted, the Operator creates a project with the resource name orgId: 5b890e0feacf0b76ff3e7183 # this is a required parameter baseUrl: https://ops.example.com:8443
EOFキー | タイプ | 説明 | 例 |
|---|---|---|---|
| string |
| |
| string |
| |
| string | MongoDB Ops Managerプロジェクトのラベル。 Kubernetes Operator は、 MongoDB Ops Managerプロジェクトが存在しない場合は、それを作成します。 Cloud ManagerまたはMongoDB Ops Manager組織で既存のプロジェクトを使用するには、 Cloud ManagerまたはMongoDB Ops Managerページの左上にある All Clusters リンクをクリックし、Search で名前を検索して、 |
|
| string | 必須。 または 組織 を一意に識別する24 文字の 16stringCloud Manager MongoDB Ops Manager進 。 Kubernetes演算子を使用して、MongoDB Cloud ManagerMongoDB Ops Managerおよび バージョン6.0 .x 以降で リソースを配置できます。 Atlas 演算子を使用して、MongoDB リソースを Atlas に配置できます。
既存の Cloud Managerまたは 組織内に新しいプロジェクトを作成するには、 組織プロジェクト作成者MongoDB Ops Manager ロールが必要です。
|
|
| string | FQDN とポート番号を含む MongoDB Ops Manager アプリケーションへの URL 。 重要: を Operator で配置し、 MongoDB Ops Managerが配置先のKubernetes クラスターのMongoDB Ops Manager MongoDB外部 に配置された データベースリソースを管理する場合、Kubernetes Cloud Manager を使用している場合は、 |
|
MongoDBレプリカセットリソースを配置します。
次のYAMLファイルをコピーして保存します。
apiVersion: mongodb.com/v1kind: MongoDBmetadata: name: demo-mongodb-cluster-1 namespace: mongodbspec: 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次のコマンドを実行します:
kubectl apply -f <replica-set-conf>.yaml
データベースユーザーのパスワードを使用してシークレットを作成します。
MongoDB データベースユーザーのパスワードを選択し、シークレットに保存します。このパスワードは、任意の値にできます。次のステップでデータベースユーザーを作成する際に、このシークレットを参照します。
パスワードはクリアテキストとして(stringDataを使用)、または Base64 エンコード値として(dataを使用)保存できます。
クリアテキスト パスワードの場合は、次のYAMLファイルを作成して保存します。
apiVersion: v1kind: Secretmetadata: name: mms-user-1-password # corresponds to user.spec.passwordSecretKeyRef.nametype: OpaquestringData: password: <my-plain-text-password> # corresponds to user.spec.passwordSecretKeyRef.keybase64 でエンコードされたパスワードの場合は、次の YAML ファイルを作成して保存します。
apiVersion: v1kind: Secretmetadata: name: mms-user-1-password # corresponds to user.spec.passwordSecretKeyRef.nametype: Opaquedata: password: <base-64-encoded-password> # corresponds to user.spec.passwordSecretKeyRef.keyプレースホルダーを選択したパスワードに置き換えます。詳細については、「 SCRAM 認証を使用したデータベースユーザーの管理」を参照してください。
データベースユーザーを作成します。
次のMongoDB ユーザー リソース仕様ファイルをコピーして保存します。
apiVersion: mongodb.com/v1kind: MongoDBUsermetadata: name: mms-scram-user-1spec: 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
MongoDBレプリカセットに接続します。
MongoDB Ops Managerアプリケーションで次の手順を実行します。
左側のナビゲーションで [ Deployment ] をクリックします。
をクリックします接続する配置の 。
[Connect to this instance] をクリックします。
配置に接続するには、ターミナルで接続コマンドを実行します。