-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.tf
150 lines (131 loc) · 3.54 KB
/
main.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
# Create secret containing Hetzner Cloud API token
resource "kubernetes_secret" "hcloud_token" {
metadata {
name = "hcloud"
namespace = "kube-system"
}
data = {
token = var.hcloud_token
network = var.network_name
}
}
# Create Hetzner cloud controller service account
resource "kubernetes_service_account" "cloud_controller_manager" {
metadata {
name = "cloud-controller-manager"
namespace = "kube-system"
}
}
# Create cluster role binding
resource "kubernetes_cluster_role_binding" "system_cloud_controller_manager" {
metadata {
name = "system:cloud-controller-manager"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = "cluster-admin"
}
subject {
kind = "ServiceAccount"
name = "cloud-controller-manager"
namespace = "kube-system"
}
}
# Deploy cloud controller
resource "kubernetes_deployment" "hcloud_cloud_controller_manager" {
metadata {
name = "hcloud-cloud-controller-manager"
namespace = "kube-system"
}
spec {
replicas = 1
revision_history_limit = 2
selector {
match_labels = {
app = "hcloud-cloud-controller-manager"
}
}
template {
metadata {
labels = {
app = "hcloud-cloud-controller-manager"
}
annotations = {
"scheduler.alpha.kubernetes.io/critical-pod" = ""
}
}
spec {
automount_service_account_token = true # override Terraform's default false - https://github.com/kubernetes/kubernetes/issues/27973#issuecomment-462185284
service_account_name = "cloud-controller-manager"
dns_policy = "Default"
toleration {
key = "node.cloudprovider.kubernetes.io/uninitialized"
value = true
effect = "NoSchedule"
}
toleration {
key = "CriticalAddonsOnly"
operator = "Exists"
}
toleration {
key = "node-role.kubernetes.io/master"
effect = "NoSchedule"
}
toleration {
key = "node-role.kubernetes.io/control-plane"
effect = "NoSchedule"
}
toleration {
key = "node.kubernetes.io/not-ready"
effect = "NoSchedule"
}
host_network = true
container {
image = "hetznercloud/hcloud-cloud-controller-manager:${var.ccm_image_version}"
name = "hcloud-cloud-controller-manager"
command = [
"/bin/hcloud-cloud-controller-manager",
"--cloud-provider=hcloud",
"--leader-elect=false",
"--allow-untagged-cloud",
"--allocate-node-cidrs=true",
"--cluster-cidr=${var.cluster_cidr}"
]
resources {
requests = {
cpu = "100m"
memory = "50Mi"
}
}
env {
name = "NODE_NAME"
value_from {
field_ref {
field_path = "spec.nodeName"
}
}
}
env {
name = "HCLOUD_TOKEN"
value_from {
secret_key_ref {
name = "hcloud"
key = "token"
}
}
}
env {
name = "HCLOUD_NETWORK"
value_from {
secret_key_ref {
name = "hcloud"
key = "network"
}
}
}
}
}
}
}
}