Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

クラスターのインスタンス数を増やす #42

Merged
merged 3 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion terraform/control-plane-disk.tf
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 2 additions & 2 deletions terraform/control-plane-server.tf
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion terraform/network-external.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions terraform/output.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/router-disk.tf
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 2 additions & 2 deletions terraform/router-server.tf
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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]
Expand Down
69 changes: 26 additions & 43 deletions terraform/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,118 +6,101 @@ 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
}
}
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
}
}
4 changes: 2 additions & 2 deletions terraform/worker-node-disk.tf
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions terraform/worker-node-server.tf
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -13,12 +13,12 @@ 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]
# note_ids = ["<ID>", "<ID>"]
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)
}
Expand Down
Loading