-
Notifications
You must be signed in to change notification settings - Fork 3
/
loadbalancer.tf
140 lines (120 loc) · 3.71 KB
/
loadbalancer.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Load Balancing For HA Applications via Yandex Load Balancer
# see https://github.com/redhat-cop/openshift-playbooks/blob/master/playbooks/installation/load_balancing.adoc
locals {
master_mapping = flatten([for i, master in yandex_compute_instance.master :
{
ip_address = master.network_interface.0.ip_address,
subnet_id = master.network_interface.0.subnet_id
}])
infra_mapping = flatten([for i, infra in yandex_compute_instance.infra :
{
ip_address = infra.network_interface.0.ip_address,
subnet_id = infra.network_interface.0.subnet_id
}])
}
################################################################
# PUBLIC target group and load balancer for MASTER nodes
################################################################
resource "yandex_lb_target_group" "okd_master_target" {
name = "lb-target-group-mgmt-public"
dynamic "target" {
for_each = local.master_mapping
content{
address = target.value.ip_address
subnet_id = target.value.subnet_id
}
}
}
resource "yandex_lb_network_load_balancer" "okd_master_public_lb" {
name = "mgmt-public-load-balancer"
type = "external"
listener {
name = "listener-mgmt-8443"
port = 9443
protocol = "tcp"
external_address_spec {
ip_version = "ipv4"
}
}
attached_target_group {
target_group_id = yandex_lb_target_group.okd_master_target.id
healthcheck {
name = "tcp-check"
http_options {
port = 9443 # port nu,ber changed from defaul 8443 - we can't connect multiple load balancer to the same port for the same target
path = "/"
}
}
}
}
################################################################
# INTERNAL target group and load balancer for MASTER nodes
################################################################
resource "yandex_lb_network_load_balancer" "okd_master_internal_lb" {
name = "mgmt-intgernal-load-balancer"
type = "internal"
listener {
name = "listener-mgmt-8443"
port = 8443
protocol = "tcp"
internal_address_spec {
subnet_id = element(yandex_vpc_subnet.subnet, 0).id # Create lb in first subnet by default
ip_version = "ipv4"
}
}
attached_target_group {
target_group_id = yandex_lb_target_group.okd_master_target.id
healthcheck {
name = "tcp-check"
http_options {
port = 8443
path = "/"
}
}
}
}
################################################################
# INTERNAL target group and load balancer for INFRA nodes
################################################################
resource "yandex_lb_target_group" "okd_infra_internal_target" {
name = "lb-target-group-infra-internal"
dynamic "target" {
for_each = local.infra_mapping
content{
address = target.value.ip_address
subnet_id = target.value.subnet_id
}
}
}
resource "yandex_lb_network_load_balancer" "okd_infra_internal_lb" {
name = "infra-internal-load-balancer"
type = "internal"
listener {
name = "listener-infra-80"
port = 80
protocol = "tcp"
internal_address_spec {
subnet_id = element(yandex_vpc_subnet.subnet, 0).id # Create lb in first subnet by default
ip_version = "ipv4"
}
}
listener {
name = "listener-infra-443"
port = 443
protocol = "tcp"
internal_address_spec {
subnet_id = element(yandex_vpc_subnet.subnet, 0).id # Create lb in first subnet by default
ip_version = "ipv4"
}
}
attached_target_group {
target_group_id = yandex_lb_target_group.okd_infra_internal_target.id
healthcheck {
name = "tcp-check"
http_options {
port = 8443
path = "/"
}
}
}
}