1
구성도
PPT
2
파일 5개
main.tf
nat.tf
nks.tf
variables.tf
versions.tf
NAT.tf 파일 생성
DB 라우팅을 분리함.
3
[root@ngame-web01-dev 6]# more *.tf
::::::::::::::
main.tf
::::::::::::::
provider "ncloud" {
support_vpc = true
region = "KR"
access_key = var.access_key
secret_key = var.secret_key
}
resource "ncloud_login_key" "key_vpc" {
key_name = var.name_vpc
}
resource "ncloud_vpc" "vpc_vpc" {
name = var.name_vpc
ipv4_cidr_block = "10.0.0.0/21"
}
resource "ncloud_subnet" "subnet_pri1" {
name = var.name_pri1
vpc_no = ncloud_vpc.vpc_vpc.id
subnet = cidrsubnet(ncloud_vpc.vpc_vpc.ipv4_cidr_block,2 ,0 )
zone = "KR-1"
network_acl_no = ncloud_vpc.vpc_vpc.default_network_acl_no
subnet_type = "PRIVATE"
// PUBLIC(Public) | PRIVATE(Private)
}
resource "ncloud_subnet" "subnet_pub1" {
name = var.name_pub1
vpc_no = ncloud_vpc.vpc_vpc.id
subnet = cidrsubnet(ncloud_vpc.vpc_vpc.ipv4_cidr_block,3 , 2)
zone = "KR-1"
network_acl_no = ncloud_vpc.vpc_vpc.default_network_acl_no
subnet_type = "PUBLIC"
// PUBLIC(Public) | PRIVATE(Private)
}
resource "ncloud_subnet" "subnet_pri-db1" {
name = var.name_pri-db1
vpc_no = ncloud_vpc.vpc_vpc.id
subnet = cidrsubnet(ncloud_vpc.vpc_vpc.ipv4_cidr_block,3 , 3)
zone = "KR-1"
network_acl_no = ncloud_vpc.vpc_vpc.default_network_acl_no
subnet_type = "PRIVATE"
// PUBLIC(Public) | PRIVATE(Private)
}
resource "ncloud_subnet" "subnet_pub-nat1" {
name = var.name_pub-nat1
vpc_no = ncloud_vpc.vpc_vpc.id
subnet = cidrsubnet(ncloud_vpc.vpc_vpc.ipv4_cidr_block,3 , 4)
zone = "KR-1"
network_acl_no = ncloud_vpc.vpc_vpc.default_network_acl_no
subnet_type = "PUBLIC"
usage_type = "NATGW"
// PUBLIC(Public) | PRIVATE(Private)
}
resource "ncloud_subnet" "subnet_pub-lb1" {
name = var.name_pub-lb1
vpc_no = ncloud_vpc.vpc_vpc.id
subnet = cidrsubnet(ncloud_vpc.vpc_vpc.ipv4_cidr_block,3 , 5)
zone = "KR-1"
network_acl_no = ncloud_vpc.vpc_vpc.default_network_acl_no
subnet_type = "PUBLIC"
usage_type = "LOADB"
// PUBLIC(Public) | PRIVATE(Private)
}
resource "ncloud_subnet" "subnet_pri-lb1" {
name = var.name_pri-lb1
vpc_no = ncloud_vpc.vpc_vpc.id
subnet = cidrsubnet(ncloud_vpc.vpc_vpc.ipv4_cidr_block,3 , 6)
zone = "KR-1"
network_acl_no = ncloud_vpc.vpc_vpc.default_network_acl_no
subnet_type = "PRIVATE"
// PUBLIC(Public) | PRIVATE(Private)
usage_type = "LOADB"
}
::::::::::::::
nat.tf
::::::::::::::
resource "ncloud_route_table" "route_table_pri1" {
name = var.name_pri1
vpc_no = ncloud_vpc.vpc_vpc.id
supported_subnet_type = "PRIVATE"
}
resource "ncloud_route_table_association" "subnet_pri-db1" {
route_table_no = ncloud_route_table.route_table_pri1.id
subnet_no = ncloud_subnet.subnet_pri-db1.id
}
# NAT Gateway
resource "ncloud_nat_gateway" "nat_gateway_scn_02" {
vpc_no = ncloud_vpc.vpc_vpc.id
subnet_no = ncloud_subnet.subnet_pub-nat1.id
zone = "KR-1"
name = var.name_pub-nat1
}
# Route Table
resource "ncloud_route" "route_scn_02_nat" {
route_table_no = ncloud_vpc.vpc_vpc.default_private_route_table_no
#route_table_no = ncloud_route_table.route_table_pri1.id
destination_cidr_block = "0.0.0.0/0"
target_type = "NATGW"
target_name = ncloud_nat_gateway.nat_gateway_scn_02.name
target_no = ncloud_nat_gateway.nat_gateway_scn_02.id
}
::::::::::::::
nks.tf
::::::::::::::
resource "ncloud_nks_cluster" "cluster" {
cluster_type = "SVR.VNKS.STAND.C002.M008.NET.SSD.B050.G002"
k8s_version = data.ncloud_nks_versions.version.versions.0.value
login_key_name = ncloud_login_key.loginkey.key_name
name = "sample-cluster"
lb_private_subnet_no = ncloud_subnet.subnet_pri-lb1.id
lb_public_subnet_no = ncloud_subnet.subnet_pub-lb1.id
kube_network_plugin = "cilium"
subnet_no_list = [ ncloud_subnet.subnet_pri1.id ]
vpc_no = ncloud_vpc.vpc_vpc.id
zone = "KR-1"
log {
audit = true
}
}
data "ncloud_nks_server_images" "image"{
hypervisor_code = "XEN"
filter {
name = "label"
values = ["ubuntu-20.04"]
regex = true
}
}
data "ncloud_nks_server_products" "nks_products"{
software_code = data.ncloud_nks_server_images.image.images[0].value
zone = "KR-1"
filter {
name = "product_type"
values = [ "STAND"]
}
filter {
name = "cpu_count"
values = [ "2"]
}
filter {
name = "memory_size"
values = [ "8GB" ]
}
}
resource "ncloud_nks_node_pool" "node_pool" {
cluster_uuid = ncloud_nks_cluster.cluster.uuid
node_pool_name = "pool1"
node_count = 1
software_code = data.ncloud_nks_server_images.image.images[0].value
product_code = data.ncloud_nks_server_products.nks_products.products[0].value
subnet_no_list = [ncloud_subnet.subnet_pri1.id]
autoscale {
enabled = true
min = 1
max = 2
}
}
data "ncloud_nks_versions" "version" {
filter {
name = "value"
values = [var.nks_version]
regex = true
}
}
resource "ncloud_login_key" "loginkey" {
key_name = var.login_key
}
::::::::::::::
variables.tf
::::::::::::::
variable name_vpc {
default = "agame-dev-vpc8"
}
variable name_pri1 {
default = "agame-dev-pri1"
}
variable name_pub1 {
default = "agame-dev-pub1"
}
variable name_pri-db1 {
default = "agame-dev-pri-db1"
}
variable name_pub-nat1 {
default = "agame-dev-pub-nat1"
}
variable name_pub-lb1 {
default = "agame-dev-pub-lb1"
}
variable name_pri-lb1 {
default = "agame-dev-pri-lb1"
}
variable client_ip {
default = "3.3.3.3"
}
variable access_key {
default = "ncp_iam_Bsp5"
}
variable secret_key {
default = "ncp_iam_BPK9DLNrW50nQ"
}
variable nks_version {
default = "1.28"
}
variable name_scn_02 {
default = "tf-scn02"
}
variable login_key {
default = "agame-k8s12"
}
::::::::::::::
versions.tf
::::::::::::::
terraform {
required_providers {
ncloud = {
source = "navercloudplatform/ncloud"
}
}
required_version = ">= 0.13"
}
[root@ngame-web01-dev
4
terraform init
terraform plan
terraform apply -auto-approve
5
삭제
terraform destroy -auto-approve
6
여러번 실행시 로그인키 중복 오류 함.
vi variables.tf
login 키 이름 수정 필요!!
terraform apply -auto-approve
7
ncloud_nks_cluster.cluster: Still creating... [16m50s elapsed]
ncloud_nks_cluster.cluster: Still creating... [17m0s elapsed]
ncloud_nks_cluster.cluster: Still creating... [17m10s elapsed]
ncloud_nks_cluster.cluster: Still creating... [17m20s elapsed]
ncloud_nks_cluster.cluster: Creation complete after 17m21s [id=18528358-44aa-433f-9e79-e1e7f137569d]
ncloud_nks_node_pool.node_pool: Creating...
ncloud_nks_node_pool.node_pool: Still creating... [10s elapsed]
ncloud_nks_node_pool.node_pool: Still creating... [20s elapsed]
ncloud_nks_node_pool.node_pool: Still creating... [30s elapsed]
ncloud_nks_node_pool.node_pool: Still creating... [40s elapsed]
https://vclock.kr/timer/#countdown=00:10:00&enabled=0&seconds=0&sound=xylophone&loop=1
8
참고
https://brunch.co.kr/@topasvga/3975
1
https://brunch.co.kr/@topasvga/3974
2
k get nodes
NAME STATUS ROLES AGE VERSION
pool1-w-5pf4 Ready <none> 11m v1.28.10
pool1-w-5pf5 Ready <none> 105s v1.28.10
[root@ngame-web01-dev ~]#
3
kw
4
감사합니다.