Skip to content

Commit

Permalink
upcloud: add server groups and target port for lb
Browse files Browse the repository at this point in the history
  • Loading branch information
robinAwallace committed Feb 27, 2023
1 parent c950bff commit 63e0de5
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 3 deletions.
4 changes: 4 additions & 0 deletions contrib/terraform/upcloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ terraform destroy --var-file cluster-settings.tfvars \
* `loadbalancer_plan`: Plan to use for load balancer *(development|production-small)*
* `loadbalancers`: Ports to load balance and which machines to forward to. Key of this object will be used as the name of the load balancer frontends/backends
* `port`: Port to load balance.
* `target_port`: Port to the backend servers.
* `backend_servers`: List of servers that traffic to the port should be forwarded to.
* `server_groups`: Group servers together
* `servers`: The servers that should be included in the group.
* `anti_affinity`: If anti-affinity should be enabled, try to spread the VMs out on separate nodes.
18 changes: 18 additions & 0 deletions contrib/terraform/upcloud/cluster-settings.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,28 @@ loadbalancer_plan = "development"
loadbalancers = {
# "http" : {
# "port" : 80,
# "target_port" : 80,
# "backend_servers" : [
# "worker-0",
# "worker-1",
# "worker-2"
# ]
# }
}

server_groups = {
# "control-plane" = {
# servers = [
# "master-0"
# ]
# anti_affinity = true
# },
# "workers" = {
# servers = [
# "worker-0",
# "worker-1",
# "worker-2"
# ]
# anti_affinity = true
# }
}
2 changes: 2 additions & 0 deletions contrib/terraform/upcloud/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module "kubernetes" {
loadbalancer_enabled = var.loadbalancer_enabled
loadbalancer_plan = var.loadbalancer_plan
loadbalancers = var.loadbalancers

server_groups = var.server_groups
}

#
Expand Down
10 changes: 9 additions & 1 deletion contrib/terraform/upcloud/modules/kubernetes-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ locals {
lb_backend_servers = flatten([
for lb_name, loadbalancer in var.loadbalancers : [
for backend_server in loadbalancer.backend_servers : {
port = loadbalancer.port
port = loadbalancer.target_port
lb_name = lb_name
server_name = backend_server
}
Expand Down Expand Up @@ -548,3 +548,11 @@ resource "upcloud_loadbalancer_static_backend_member" "lb_backend_member" {
max_sessions = var.loadbalancer_plan == "production-small" ? 50000 : 1000
enabled = true
}

resource "upcloud_server_group" "server_groups" {
for_each = var.server_groups
title = each.key
anti_affinity = each.value.anti_affinity
labels = {}
members = [for server in each.value.servers : merge(upcloud_server.master, upcloud_server.worker)[server].id]
}
10 changes: 10 additions & 0 deletions contrib/terraform/upcloud/modules/kubernetes-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ variable "loadbalancers" {

type = map(object({
port = number
target_port = number
backend_servers = list(string)
}))
}

variable "server_groups" {
description = "Server groups"

type = map(object({
anti_affinity = bool
servers = list(string)
}))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
upcloud = {
source = "UpCloudLtd/upcloud"
version = "~>2.5.0"
version = "~>2.7.1"
}
}
required_version = ">= 0.13"
Expand Down
18 changes: 18 additions & 0 deletions contrib/terraform/upcloud/sample-inventory/cluster.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,28 @@ loadbalancer_plan = "development"
loadbalancers = {
# "http" : {
# "port" : 80,
# "target_port" : 80,
# "backend_servers" : [
# "worker-0",
# "worker-1",
# "worker-2"
# ]
# }
}

server_groups = {
# "control-plane" = {
# servers = [
# "master-0"
# ]
# anti_affinity = true
# },
# "workers" = {
# servers = [
# "worker-0",
# "worker-1",
# "worker-2"
# ]
# anti_affinity = true
# }
}
12 changes: 12 additions & 0 deletions contrib/terraform/upcloud/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,19 @@ variable "loadbalancers" {

type = map(object({
port = number
target_port = number
backend_servers = list(string)
}))
default = {}
}

variable "server_groups" {
description = "Server groups"

type = map(object({
anti_affinity = bool
servers = list(string)
}))

default = {}
}
2 changes: 1 addition & 1 deletion contrib/terraform/upcloud/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
upcloud = {
source = "UpCloudLtd/upcloud"
version = "~>2.5.0"
version = "~>2.7.1"
}
}
required_version = ">= 0.13"
Expand Down

0 comments on commit 63e0de5

Please sign in to comment.