forked from solidnerd/terraform-k8s-hcloud
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path02-kube-init.tf
executable file
·157 lines (131 loc) · 4.03 KB
/
02-kube-init.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
resource "null_resource" "init_main_master" {
connection {
host = hcloud_server.master[0].ipv4_address
type = "ssh"
port = var.ssh_port
private_key = file(var.ssh_private_key)
}
provisioner "file" {
source = "files/10-kubeadm.conf"
destination = "/root/10-kubeadm.conf"
}
provisioner "file" {
source = "scripts/kube-bootstrap.sh"
destination = "/root/kube-bootstrap.sh"
}
provisioner "remote-exec" {
inline = [
"DOCKER_VERSION=${var.docker_version} KUBERNETES_VERSION=${var.kubernetes_version} MASTER_INDEX=1 bash /root/kube-bootstrap.sh"]
}
provisioner "file" {
source = "scripts/kube-main-master.sh"
destination = "/root/kube-main-master.sh"
}
provisioner "local-exec" {
command = "mkdir -p ${path.module}/secrets && touch ${path.module}/secrets/kubeadm_control_plane_join"
}
provisioner "remote-exec" {
inline = [
"FEATURE_GATES=${var.feature_gates} LB_IP=${hcloud_load_balancer.kube_load_balancer.ipv4} bash /root/kube-main-master.sh"]
}
provisioner "local-exec" {
command = "bash scripts/copy-kubeadm-token.sh"
environment = {
SSH_PRIVATE_KEY = var.ssh_private_key
SSH_USERNAME = "root"
SSH_PORT = var.ssh_port
SSH_HOST = hcloud_server.master[0].ipv4_address
TARGET = "${path.module}/secrets/"
}
}
}
resource "null_resource" "init_masters" {
depends_on = [null_resource.init_main_master]
count = var.master_count
connection {
host = hcloud_server.master[count.index].ipv4_address
type = "ssh"
port = var.ssh_port
private_key = file(var.ssh_private_key)
}
provisioner "file" {
source = "files/10-kubeadm.conf"
destination = "/root/10-kubeadm.conf"
}
provisioner "file" {
source = "scripts/kube-bootstrap.sh"
destination = "/root/kube-bootstrap.sh"
}
provisioner "remote-exec" {
inline = [
"DOCKER_VERSION=${var.docker_version} KUBERNETES_VERSION=${var.kubernetes_version} MASTER_INDEX=${count.index} bash /root/kube-bootstrap.sh"]
}
provisioner "file" {
source = "scripts/kube-master.sh"
destination = "/root/kube-master.sh"
}
provisioner "file" {
source = "${path.module}/secrets/kubeadm_control_plane_join"
destination = "/tmp/kubeadm_control_plane_join"
}
provisioner "remote-exec" {
inline = [
"FEATURE_GATES=${var.feature_gates} MASTER_INDEX=${count.index} bash /root/kube-master.sh"]
}
}
resource "null_resource" "init_workers" {
depends_on = [null_resource.init_masters]
count = var.node_count
connection {
host = hcloud_server.node[count.index].ipv4_address
type = "ssh"
port = var.ssh_port
private_key = file(var.ssh_private_key)
}
provisioner "file" {
source = "files/10-kubeadm.conf"
destination = "/root/10-kubeadm.conf"
}
provisioner "file" {
source = "scripts/kube-bootstrap.sh"
destination = "/root/kube-bootstrap.sh"
}
provisioner "remote-exec" {
inline = [
"DOCKER_VERSION=${var.docker_version} KUBERNETES_VERSION=${var.kubernetes_version} bash /root/kube-bootstrap.sh"]
}
provisioner "remote-exec" {
inline = [
"kubeadm token create --print-join-command > /tmp/kubeadm_join_${count.index + 1}"]
connection {
host = hcloud_server.master[0].ipv4_address
type = "ssh"
port = var.ssh_port
user = "root"
private_key = file(var.ssh_private_key)
}
}
provisioner "local-exec" {
command = "bash scripts/copy-join-token.sh"
environment = {
SSH_PRIVATE_KEY = var.ssh_private_key
SSH_USERNAME = "root"
SSH_PORT = var.ssh_port
SSH_HOST = hcloud_server.master[0].ipv4_address
TARGET = "${path.module}/secrets/"
ID = count.index + 1
}
}
provisioner "file" {
source = "${path.module}/secrets/kubeadm_join_${count.index + 1}"
destination = "/tmp/kubeadm_join"
}
provisioner "file" {
source = "scripts/kube-node.sh"
destination = "/root/kube-node.sh"
}
provisioner "remote-exec" {
inline = [
"bash /root/kube-node.sh"]
}
}