brunch
매거진 kakao cloud

카카오 클라우드 4탄-14.테라폼으로 몽고디비 설치

by Master Seo

테라폼으로 몽고디비 설치해보자.


<0> 사전 준비

<1> 로키 리눅스에 테라폼 설치

<2> 설정파일 작성하기

<3> 예제 설치

<4> 클라우드 리소스 생성하기

<5> 결과 확인

<6> 참고 사이트



<0> 사전 준비


https://kakaocloud.com/


1

key Pair - 서버 접속용 키페어 확인

public subnet 확인 - vpc에서 확인

access-key , secret-key 확인



2

사용할 리소스 정보


가상머신

handson-node-1 ,2 ,3 = 우분트 20.04


볼륨

mongo-data-volume-1 ,2,3 500



<1> 로키 리눅스에 테라폼 설치



sudo yum install -y yum-utils

sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo

sudo dnf repolist

sudo yum -y install terraform


terraform version

Terraform v1.7.3




<2> 설정파일 작성하기


mkdir -p ~/.config/openstack/


cat << EOF > ~/.config/openstack/clouds.yaml

clouds:

hands-on:

region_name: 'kr-central-2'

interface: 'public'

auth_type: "v3applicationcredential"

auth:

auth_url: 'https://iam.kakaoi.io/identity/v3'

application_credential_id: "${사용자 액세스 키 ID}"

application_credential_secret: "${사용자 액세스 보안 키}"

EOF




<3> 예제 설치



1

git clone -b terraform-mongodb https://github.com/kakaoenterprise/kc-handson-config.git


2

cd ./kc-handson-config


3

vim variables.tf



4

사용자 키페어 입력.

# network

variable public_network_cidr {

type = string

default = "${PUBLIC_NETWORK_CIDR}"

}

# key

variable "sshkey" {

type = string

default = "${USER_ACCESS_KEY_NAME}"

}

variable "replicaset_name" {

type = string

default = "${REPLICASET_NAME}"

}

...



<4> 클라우드 리소스 생성하기



1

export OS_CLOUD=hands-on


2

terraform init


3

terraform plan



Plan: 16 to add, 0 to change, 0 to destroy.

│ Warning: Argument is deprecated

│ with provider["registry.terraform.io/terraform-provider-openstack/openstack"],

│ on require.tf line 11, in provider "openstack":

│ 11: provider "openstack" {

│ Users not using loadbalancer resources can ignore this message. Support for neutron-lbaas will be removed on next major release. Octavia will be the only supported method for loadbalancer resources. Users

│ using octavia will have to remove 'use_octavia' option from the provider configuration block. Users using neutron-lbaas will have to migrate/upgrade to octavia.

Do you want to perform these actions?

Terraform will perform the actions described above.

Only 'yes' will be accepted to approve.

Enter a value: yes

Apply cancelled



4

terraform apply




<5> 결과 확인



1

vm > instance 에서 인스턴스 확인



2

볼륨에서 볼륨 확인.



3

몽고디비 접속을 위해 베스천 생성.

베스천은 우분트로 설치한다.

Bastion 호스트 10000번 포트에 대한 접근을 Replicaset의 Primary 노드인 handson-mongodb-1 인스턴스 사설 IP의 22번 포트로 포워딩.


https://docs.kakaocloud.com/tutorial/fundamentals/vm-based-web




4

Bastion 인스턴스를 통한 MongoDB 인스턴스 ssh 접속을 시도합니다.

ssh -i ${PRIVATE_KEY_FILE} ubuntu@${BASTION_PUBLIC_IP} -p 10000



5

MongoDB 인스턴스에 접속한 후, 아래 명령을 실행하여 Replicaset이 구성되었는지 확인

mongosh --eval 'rs.config()'



6

모든 작업 확인후 리소스 제거

terraform destroy





<6> 참고 사이트


https://docs.kakaocloud.com/tutorial/automation/terraform-mongodb-replicaset#step-3-%EC%98%88%EC%A0%9C-%EC%84%A4%EC%B9%98-%EB%B0%8F-%EC%9E%91%EC%84%B1%ED%95%98%EA%B8%B0



몰아보기

https://brunch.co.kr/@topasvga/3651


감사합니다.

keyword
매거진의 이전글카카오클라우드 4탄-13.테라폼으로 웹서비스 자동화