-
Notifications
You must be signed in to change notification settings - Fork 5
/
autoscaling_nodes.tf
108 lines (93 loc) · 3.19 KB
/
autoscaling_nodes.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
data "aws_subnet" "region_1b" {
id = "${var.subnets[1]}"
}
data "aws_subnet" "region_1c" {
id = "${var.subnets[2]}"
}
data "template_file" "nodes" {
template = "${file("${path.module}/scripts/userdata.tpl")}"
vars {
s3_id = "${aws_s3_bucket.cluster.id}"
role = "node"
proxy = "${replace("${var.proxy_servers}", ",", " ")}"
volume = ""
load_balancer_dns = "${aws_lb.master.dns_name}"
net_plugin = "${var.cluster_network_plugin}"
}
}
resource "aws_security_group" "nodes" {
name_prefix = "${var.name}-nodes"
description = "${var.name}-nodes"
vpc_id = "${var.vpc}"
tags = "${var.additional_tags}"
}
resource "aws_security_group_rule" "nodes-self" {
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
self = true
security_group_id = "${aws_security_group.nodes.id}"
}
resource "aws_security_group_rule" "nodes-ssh" {
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_security_group.nodes.id}"
}
resource "aws_security_group_rule" "nodes-egress" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_security_group.nodes.id}"
}
resource "aws_security_group_rule" "master-node-communication" {
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
source_security_group_id = "${aws_security_group.master.id}"
security_group_id = "${aws_security_group.nodes.id}"
}
resource "aws_launch_configuration" "nodes" {
name_prefix = "${var.name}-nodes-"
image_id = "${data.aws_ami.ubuntu.id}"
instance_type = "${var.node_instance_type}"
security_groups = ["${aws_security_group.nodes.id}"]
key_name = "${var.ssh_key}"
user_data = "${data.template_file.nodes.rendered}"
iam_instance_profile = "${aws_iam_instance_profile.cluster.id}"
root_block_device {
volume_size = 60
volume_type = "gp2"
}
lifecycle {
create_before_destroy = true
ignore_changes = ["image_id"]
}
}
resource "aws_autoscaling_group" "nodes" {
name_prefix = "${var.name}-nodes-"
max_size = "${var.node_asg_max}"
min_size = "${var.node_asg_min}"
health_check_grace_period = 300
health_check_type = "EC2"
desired_capacity = "${var.node_asg_desired}"
force_delete = true
launch_configuration = "${aws_launch_configuration.nodes.name}"
vpc_zone_identifier = ["${data.aws_subnet.region_1b.id}", "${data.aws_subnet.region_1c.id}"]
tags = ["${concat(
list(map("key", "Name", "value", "${var.name}-node", "propagate_at_launch", true),
map("key", "KubernetesCluster", "value", "${var.name}", "propagate_at_launch", true),
map("key", "k8s.io/role/node", "value", 1, "propagate_at_launch", true),
),
local.tags_asg_format
)}"]
lifecycle {
create_before_destroy = true
}
}