Docs Menu

Kubernetes Operator를 위한 빠른 시작

중요

이 섹션은 단일 Kubernetes 클러스터 배포에만 적용됩니다. 다중 Kubernetes 클러스터 MongoDB 배포의 경우 다중 Kubernetes 클러스터 빠른 시작을 참조하세요.

MongoDB 엔터프라이즈 Kubernetes Operator는 Kubernetes API 및 도구를 사용하여 Kubernetes 클러스터 내에서 실행 MongoDB cluster를 관리 . Kubernetes Operator는 MongoDB Cloud Manager 또는 MongoDB Ops Manager 와 함께 작동합니다. 이 튜토리얼에서는 Kubernetes Operator를 사용하여 MongoDB Cloud Manager 에서 첫 번째 MongoDB 복제본 세트 를 배포 하고 연결하는 방법을 설명합니다. Kind를 사용하여 클러스터 빠르게 설정하다 수 있습니다. 자세히 학습 Kind 를 참조하세요.

이 튜토리얼에는 다음이 필요합니다.

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

Helm을 사용하여 Kubernetes Operator를 설치하려면 리포지토리 의 지침을 참조하세요.

예시

다음 명령은 선택적 --create-namespace 옵션을 사용하여 mongodb 네임스페이스에 MongoDB Enterprise Kubernetes Operator를 설치합니다. 기본적으로 Kubernetes Operator는 default 네임스페이스를 사용합니다.

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

아직 실행하지 않았다면 다음 명령을 실행하여 생성한 네임스페이스에서 kubectl 명령을 모두 실행합니다.

kubectl config set-context $(kubectl config current-context) --namespace=mongodb
4
  1. 클라우드 관리자 UI에서 Kubernetes 설정 페이지로 이동합니다.

  2. Create New API Keys 또는 Use Existing API Keys를 클릭합니다.

  3. 양식을 작성합니다. 자세히 알아보려면 Cloud Manager에 대한 프로그래밍 방식의 액세스를 참조하세요.

  4. Generate Key and YAML를 클릭합니다.

5

생성된 config-map.yaml 파일을 복사하여 저장합니다.

예시:

apiVersion: v1
kind: ConfigMap
metadata:
name: my-project
namespace: mongodb
data:
baseUrl: https://cloud.mongodb.com
projectName: my-project # this is an optional parameter
orgId: 5ecd252f8c1a75033c74106c # this is a required parameter

자세한 내용은 파라미터 설명을 참조하십시오.

6

생성된 secret.yaml 파일을 복사하여 저장합니다.

예시:

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

보안을 위해 MongoDB 클라우드 관리자는 이 파일을 한 번만 표시합니다.

7

다음 명령을 실행합니다:

kubectl apply -f secret.yaml -f config-map.yaml
8
  1. 다음 YAML 파일을 복사하고 저장합니다.

    apiVersion: mongodb.com/v1
    kind: MongoDB
    metadata:
    name: demo-mongodb-cluster-1
    namespace: mongodb
    spec:
    members: 3
    version: 4.4.5-ent
    type: ReplicaSet
    security:
    authentication:
    enabled: true
    modes: ["SCRAM"]
    cloudManager:
    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
9

일반 텍스트 비밀번호 또는 Base64로 인코딩된 비밀번호를 사용할 수 있습니다. 일반 텍스트 암호는 stringData.password 을 사용하고 Base64로 인코딩된 암호는 data.password을 사용합니다.

참고

다음 매개변수에 대한 값을 입력합니다. 자세한 내용은 파라미터 설명을 참조하십시오.

일반 텍스트 비밀번호의 경우 다음 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
10
  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
11

Cloud Manager 또는 Ops Manager에서 새로 생성된 사용자를 볼 수 있습니다.

  1. 프로젝트의 Deployment 보기에서 Security 탭을 클릭합니다.

  2. 중첩된 MongoDB Users 탭을 클릭합니다.

12

Cloud Manager 애플리케이션에서 다음 단계를 수행합니다.

  1. 왼쪽 탐색에서 Deployment을 클릭합니다.

  2. 연결하려는 배포서버의 을 클릭합니다.

  3. Connect to this instance를 클릭합니다.

  4. 터미널에서 연결 명령을 실행하여 배포에 연결합니다.