From c4061d0b7d656cf68dffbff494da048d89aa04bb Mon Sep 17 00:00:00 2001 From: logica0419 <84759675+logica0419@users.noreply.github.com> Date: Mon, 25 Dec 2023 05:40:59 +0900 Subject: [PATCH 1/3] rename instances --- terraform/control-plane-disk.tf | 2 +- terraform/control-plane-server.tf | 4 ++-- terraform/router-disk.tf | 2 +- terraform/router-server.tf | 4 ++-- terraform/worker-node-disk.tf | 4 ++-- terraform/worker-node-server.tf | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/terraform/control-plane-disk.tf b/terraform/control-plane-disk.tf index 45601d62..06fc958e 100644 --- a/terraform/control-plane-disk.tf +++ b/terraform/control-plane-disk.tf @@ -1,6 +1,6 @@ resource "sakuracloud_disk" "k8s_control_plane_disk" { count = lookup(var.control_plane, terraform.workspace, 0) - name = "k8s-control-plane-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-control-plane-${count.index + 1}" source_archive_id = data.sakuracloud_archive.ubuntu_archive.id size = lookup(var.control_plane_disk, terraform.workspace, 0) tags = ["k8s", terraform.workspace] diff --git a/terraform/control-plane-server.tf b/terraform/control-plane-server.tf index 3b75f51d..9649833e 100644 --- a/terraform/control-plane-server.tf +++ b/terraform/control-plane-server.tf @@ -1,6 +1,6 @@ resource "sakuracloud_server" "k8s_control_plane" { count = lookup(var.control_plane, terraform.workspace, 0) - name = "k8s-control-plane-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-control-plane-${count.index + 1}" core = lookup(var.control_plane_cpu, terraform.workspace, 0) memory = lookup(var.control_plane_mem, terraform.workspace, 0) disks = [sakuracloud_disk.k8s_control_plane_disk[count.index].id] @@ -14,7 +14,7 @@ resource "sakuracloud_server" "k8s_control_plane" { user_ip_address = "192.168.100.1${count.index}" } disk_edit_parameter { - hostname = "k8s-control-plane-${count.index + 1}-${terraform.workspace}" + hostname = "k8s-${terraform.workspace}-control-plane-${count.index + 1}" password = var.cluster_pass disable_pw_auth = "true" ssh_key_ids = [sakuracloud_ssh_key_gen.gen_key.id] diff --git a/terraform/router-disk.tf b/terraform/router-disk.tf index 4c78c6bd..8bf5f57e 100644 --- a/terraform/router-disk.tf +++ b/terraform/router-disk.tf @@ -1,6 +1,6 @@ resource "sakuracloud_disk" "k8s_router_disk" { count = lookup(var.router, terraform.workspace, 0) - name = "k8s-router-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-router-${count.index + 1}" source_archive_id = data.sakuracloud_archive.ubuntu_archive.id size = lookup(var.router_disk, terraform.workspace, 0) tags = ["k8s", terraform.workspace] diff --git a/terraform/router-server.tf b/terraform/router-server.tf index 6d0b99f5..c9577e0d 100644 --- a/terraform/router-server.tf +++ b/terraform/router-server.tf @@ -1,6 +1,6 @@ resource "sakuracloud_server" "k8s_router" { count = lookup(var.router, terraform.workspace, 0) - name = "k8s-router-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-router-${count.index + 1}" core = lookup(var.router_cpu, terraform.workspace, 0) memory = lookup(var.router_mem, terraform.workspace, 0) disks = [sakuracloud_disk.k8s_router_disk[count.index].id] @@ -14,7 +14,7 @@ resource "sakuracloud_server" "k8s_router" { user_ip_address = "192.168.100.${count.index}" } disk_edit_parameter { - hostname = "k8s-router-${count.index + 1}-${terraform.workspace}" + hostname = "k8s-${terraform.workspace}-router-${count.index + 1}" password = var.cluster_pass disable_pw_auth = "true" ssh_key_ids = [sakuracloud_ssh_key_gen.gen_key.id] diff --git a/terraform/worker-node-disk.tf b/terraform/worker-node-disk.tf index b7f48feb..c7f18573 100644 --- a/terraform/worker-node-disk.tf +++ b/terraform/worker-node-disk.tf @@ -1,6 +1,6 @@ resource "sakuracloud_disk" "k8s_worker_node_disk" { count = lookup(var.worker_node, terraform.workspace, 0) - name = "k8s-worker-node-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-worker-node-${count.index + 1}" source_archive_id = data.sakuracloud_archive.ubuntu_archive.id size = lookup(var.worker_node_disk, terraform.workspace, 0) tags = ["k8s", terraform.workspace] @@ -12,7 +12,7 @@ resource "sakuracloud_disk" "k8s_worker_node_disk" { resource "sakuracloud_disk" "k8s_rook_disk" { count = lookup(var.worker_node, terraform.workspace, 0) - name = "k8s-rook-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-rook-${count.index + 1}" size = lookup(var.worker_node_rook_disk, terraform.workspace, 0) tags = ["k8s", terraform.workspace] timeouts { diff --git a/terraform/worker-node-server.tf b/terraform/worker-node-server.tf index 1538105d..889f4854 100644 --- a/terraform/worker-node-server.tf +++ b/terraform/worker-node-server.tf @@ -1,6 +1,6 @@ resource "sakuracloud_server" "k8s_worker_node" { count = lookup(var.worker_node, terraform.workspace, 0) - name = "k8s-worker-node-${count.index + 1}-${terraform.workspace}" + name = "k8s-${terraform.workspace}-worker-node-${count.index + 1}" core = lookup(var.worker_node_cpu, terraform.workspace, 0) memory = lookup(var.worker_node_mem, terraform.workspace, 0) disks = [sakuracloud_disk.k8s_worker_node_disk[count.index].id, sakuracloud_disk.k8s_rook_disk[count.index].id] @@ -13,7 +13,7 @@ resource "sakuracloud_server" "k8s_worker_node" { user_ip_address = "192.168.100.2${count.index}" } disk_edit_parameter { - hostname = "k8s-worker-node-${count.index + 1}-${terraform.workspace}" + hostname = "k8s-${terraform.workspace}-worker-node-${count.index + 1}" password = var.cluster_pass disable_pw_auth = "true" ssh_key_ids = [sakuracloud_ssh_key_gen.gen_key.id] From 8005cb476670cfbb353661565c0ebd5e88409042 Mon Sep 17 00:00:00 2001 From: logica0419 <84759675+logica0419@users.noreply.github.com> Date: Mon, 25 Dec 2023 05:48:11 +0900 Subject: [PATCH 2/3] delete wsp & extend instance number --- terraform/vars.tf | 69 ++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/terraform/vars.tf b/terraform/vars.tf index d3fdf657..6c94f998 100644 --- a/terraform/vars.tf +++ b/terraform/vars.tf @@ -6,16 +6,14 @@ variable "cluster_pass" { variable "external_subnet" { type = map(any) default = { - wsp = 28 - dev = 28 - prd = 28 + dev = 27 + prd = 27 } } variable "control_plane" { type = map(any) default = { - wsp = 3 dev = 3 prd = 3 } @@ -23,101 +21,86 @@ variable "control_plane" { variable "control_plane_cpu" { type = map(any) default = { - wsp = 4 - dev = 4 - prd = 4 + dev = 2 + prd = 2 } } variable "control_plane_mem" { type = map(any) default = { - wsp = 8 - dev = 8 - prd = 8 + dev = 2 + prd = 2 } } variable "control_plane_disk" { type = map(any) default = { - wsp = 40 - dev = 40 - prd = 40 + dev = 20 + prd = 20 } } variable "worker_node" { type = map(any) default = { - wsp = 3 - dev = 3 - prd = 3 + dev = 8 + prd = 8 } } variable "worker_node_cpu" { type = map(any) default = { - wsp = 4 - dev = 4 - prd = 4 + dev = 2 + prd = 2 } } variable "worker_node_mem" { type = map(any) default = { - wsp = 16 - dev = 8 - prd = 16 + dev = 2 + prd = 2 } } variable "worker_node_disk" { type = map(any) default = { - wsp = 40 - dev = 40 - prd = 40 + dev = 20 + prd = 20 } } - variable "worker_node_rook_disk" { type = map(any) default = { - wsp = 100 - dev = 40 - prd = 100 + dev = 20 + prd = 20 } } variable "router" { type = map(any) default = { - wsp = "1" - dev = "1" - prd = "1" - bgp = "1" + dev = 1 + prd = 1 } } - variable "router_cpu" { type = map(any) default = { - wsp = "2" - dev = "2" - prd = "2" + dev = 2 + prd = 2 } } variable "router_mem" { type = map(any) default = { - wsp = "2" - dev = "2" - prd = "2" + dev = 2 + prd = 2 } } variable "router_disk" { type = map(any) default = { - wsp = "20" - dev = "20" - prd = "20" + dev = 20 + prd = 20 } } From 61ffc65d3e28a2bf17b3e593fbb59a60fef17ac9 Mon Sep 17 00:00:00 2001 From: logica0419 <84759675+logica0419@users.noreply.github.com> Date: Mon, 25 Dec 2023 05:48:58 +0900 Subject: [PATCH 3/3] changed ip address allocation --- terraform/network-external.tf | 3 ++- terraform/output.tf | 4 ++-- terraform/worker-node-server.tf | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/terraform/network-external.tf b/terraform/network-external.tf index d10e2fac..be181770 100644 --- a/terraform/network-external.tf +++ b/terraform/network-external.tf @@ -10,7 +10,8 @@ resource "sakuracloud_internet" "k8s_external_switch" { resource "sakuracloud_subnet" "bgp_subnet" { internet_id = sakuracloud_internet.k8s_external_switch.id - next_hop = sakuracloud_internet.k8s_external_switch.ip_addresses[length(sakuracloud_internet.k8s_external_switch.ip_addresses) - 11] + next_hop = sakuracloud_server.k8s_router[0].ip_address + netmask = 28 timeouts { create = "1h" delete = "1h" diff --git a/terraform/output.tf b/terraform/output.tf index 74f58c86..d03ed5ad 100644 --- a/terraform/output.tf +++ b/terraform/output.tf @@ -1,9 +1,9 @@ output "vip_address" { - value = sakuracloud_internet.k8s_external_switch.ip_addresses[lookup(var.router, terraform.workspace, 0) + lookup(var.control_plane, terraform.workspace, 0)] + value = sakuracloud_internet.k8s_external_switch.ip_addresses[lookup(var.router, terraform.workspace, 0) + lookup(var.control_plane, terraform.workspace, 0) + lookup(var.worker_node, terraform.workspace, 0)] } output "external_address_range" { - value = format("%s/%s", sakuracloud_subnet.bgp_subnet.ip_addresses[0], lookup(var.external_subnet, terraform.workspace, 0)) + value = format("%s/%s", sakuracloud_subnet.bgp_subnet.ip_addresses[0], 28) } output "k8s_router_ip_address" { diff --git a/terraform/worker-node-server.tf b/terraform/worker-node-server.tf index 889f4854..b7fc334f 100644 --- a/terraform/worker-node-server.tf +++ b/terraform/worker-node-server.tf @@ -18,7 +18,7 @@ resource "sakuracloud_server" "k8s_worker_node" { disable_pw_auth = "true" ssh_key_ids = [sakuracloud_ssh_key_gen.gen_key.id] # note_ids = ["", ""] - ip_address = sakuracloud_internet.k8s_external_switch.ip_addresses[count.index + length(sakuracloud_internet.k8s_external_switch.ip_addresses) - 4] + ip_address = sakuracloud_internet.k8s_external_switch.ip_addresses[count.index + lookup(var.router, terraform.workspace, 0) + lookup(var.control_plane, terraform.workspace, 0)] gateway = sakuracloud_internet.k8s_external_switch.gateway netmask = lookup(var.external_subnet, terraform.workspace, 0) }