중요
이 섹션은 단일 Kubernetes 클러스터 배포에만 적용됩니다. 다중 Kubernetes cluster MongoDB deployment의 경우 개요 를 참조하세요.
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.
전제 조건
이 튜토리얼에는 다음이 필요합니다.
실행 중인 Kubernetes 클러스터.
Helm installed on your local machine.
지원되는 hardware 아키텍처에서실행되는 Kubernetes 노드.
로컬 머신에 설치된 MongoDB Shell .
Docker Desktop과 함께 Kind를 사용하는 경우, Docker Desktop 리소스 설정에서 최소 8 GB 의 메모리와 4 CPU를 할당하세요. Ops Manager 애플리케이션 위한 최소 5 GB 의 메모리와 애플리케이션 데이터베이스 및 Kubernetes Operator를 위한 추가 리소스가 필요합니다.
절차
Add the MongoDB Helm Charts for Kubernetes repository to Helm.
helm repo add mongodb https://mongodb.github.io/helm-charts
Kubernetes Operator용 MongoDB 컨트롤러 설치
Helm을 사용하여 Kubernetes Operator를 설치하려면, 리포지토리의 지침을 참조하세요.
예시
다음 명령은 선택적 --create-namespace 옵션을 사용하여 mongodb 네임스페이스 에 Kubernetes Operator용 MongoDB 컨트롤러를 설치합니다. 기본값 으로 Kubernetes Operator는 default 네임스페이스 사용합니다.
helm install kubernetes-operator mongodb/mongodb-kubernetes --namespace mongodb --create-namespace
MongoDB Ops Manager 관리자 자격 증명 시크릿을 만듭합니다.
Create a secret that contains the initial Ops Manager admin user credentials. The Kubernetes Operator uses this secret to configure the first admin user when it deploys the Ops Manager resource.
다음 명령을 실행하여 자리 표시자 값을 원하는 자격 증명으로 대체합니다.
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에 로그인하려면 이것이 필요합니다.
MongoDB Ops Manager 리소스를 배포합니다.
Copy and save the following YAML file as
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 리소스 사양을 참조하세요.
다음 명령을 실행합니다:
kubectl apply -f ops-manager.yaml
MongoDB Ops Manager 리소스가 실행 중 상태에 도달할 때까지 기다립니다.
Kubernetes Operator는 먼저 애플리케이션 데이터베이스 복제본 세트를 배포한 다음 Ops Manager 애플리케이션을 시작합니다. 이 과정에는 수분이 걸릴 수 있습니다.
다음 명령을 실행하여 리소스 상태를 추적합니다.
kubectl get om -o yaml -w
출력에 다음 단계가 표시될 때까지 기다립니다.
status: applicationDatabase: phase: Running opsManager: phase: Running
두 구성 요소 모두 Running에 도달하면 MongoDB Ops Manager URL을 조회합니다.
kubectl get om ops-manager -o jsonpath='{.status.opsManager.url}'
이 URL을 적어 두세요. 이 정보는 나중 단계의 ConfigMap에 필요합니다.
Ops Manager의 Kubernetes 연산자를 구성합니다.
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 사용:
Create New API Keys 또는 Use Existing API Keys를 클릭합니다.
양식을 작성합니다. 자세한 내용은 Kubernetes Operator에 대한 자격 증명 생성을 참조하세요.
Generate Key and YAML를 클릭합니다.
또는 다음 단계에서 ConfigMap 및 Secret을 수동으로 만들 수 있습니다.
ConfigMap을 만들고 저장합니다.
Ops Manager UI에서 ConfigMap을 생성한 경우 생성된 config-map.yaml 파일을 복사하여 저장합니다. 그렇지 않은 경우 다음 파일을 생성하여 저장합니다. status.opsManager.url에서 Ops Manager 인스턴스의 URL을 data.baseUrl 로 설정합니다.
예시:
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> 을 Ops Manager 조직 ID로 바꾸십시오. Ops Manager UI URL에서 이 값을 찾을 수 있습니다. http://<ops-manager-url>/v2#/org/<orgId>/projects.
자세한 내용은 파라미터 설명을 참조하십시오.
비밀을 만들고 저장합니다.
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>
To create Programmatic API Keys, see Create Credentials for the Kubernetes Operator.
Deploy the MongoDB replica set resource.
다음 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 다음 명령을 실행합니다:
kubectl apply -f <replica-set-conf>.yaml
데이터베이스 사용자 비밀번호로 비밀번호를 만듭니다.
Choose a password for your MongoDB database user and store it in a secret. This password can be any value you choose. You reference this secret when you create the database user in the next step.
클리어 텍스트(사용 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 인증을 사용하여 데이터베이스 사용자 관리를 참조하십시오.
데이터베이스 사용자를 생성합니다.
다음 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
Connect to the MongoDB replica set.
MongoDB Ops Manager 애플리케이션에서 다음 단계를 수행합니다.
왼쪽 탐색에서 Deployment을 클릭합니다.
연결하려는 배포서버의 을 클릭합니다.
Connect to this instance를 클릭합니다.
터미널에서 연결 명령을 실행하여 배포에 연결합니다.
다음 단계
The deployment that you created runs on a single Kind node and uses the default resource settings. To move from this evaluation deployment to a production deployment:
주요 배포서버 계획을 통해 아키텍처를 선택하고, 버전 호환성을 확인하고, Kubernetes 연산자 배포서버 범위를 설정합니다.
노드가 두 개 이상이고 볼륨 확장을 지원하는
storageClass가 있는 생산 Kubernetes 클러스터에 Kubernetes 연산자를 설치합니다.Secure the deployment with TLS, authentication, and encryption at rest.
클러스터 전체의 손실에서 벗어나야 하는 경우 여러 Kubernetes 클러스터에 배포 합니다.