-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubernetes.tf
177 lines (154 loc) · 4.15 KB
/
kubernetes.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
resource "google_service_account" "kubernetes" {
account_id = "gke-sa"
display_name = "Kubernetes default service account"
}
resource "google_project_iam_member" "kubernetes" {
for_each = toset([
"roles/clouddebugger.agent",
"roles/cloudtrace.agent",
"roles/errorreporting.writer",
"roles/logging.viewer",
"roles/logging.logWriter",
"roles/monitoring.metricWriter",
"roles/monitoring.viewer",
"roles/storage.admin",
"roles/storage.objectAdmin",
])
project = data.google_project.this.id
role = each.value
member = "serviceAccount:${google_service_account.kubernetes.email}"
}
resource "google_container_cluster" "this" {
provider = google-beta
name = "${local.project_name}-primary"
remove_default_node_pool = true
initial_node_count = 1
network = module.vpc.network_name
subnetwork = module.vpc.subnets["${data.google_client_config.this.region}/${local.subnets.private.name}"].self_link
location = data.google_client_config.this.zone
default_max_pods_per_node = 110
min_master_version = "1.21"
master_authorized_networks_config {
dynamic "cidr_blocks" {
for_each = concat([
{
cidr_block = module.vpc.subnets["${data.google_client_config.this.region}/${local.subnets.public.name}"].ip_cidr_range
display_name = "public-subnet"
},
{
cidr_block = "${google_compute_address.this.address}/32"
display_name = "VPC NAT IP"
}
], var.authorized_ips)
content {
cidr_block = lookup(cidr_blocks.value, "cidr_block", "")
display_name = lookup(cidr_blocks.value, "display_name", "")
}
}
}
pod_security_policy_config {
enabled = false
}
network_policy {
enabled = true
provider = "CALICO"
}
master_auth {
client_certificate_config {
issue_client_certificate = false
}
}
ip_allocation_policy {
cluster_secondary_range_name = local.subnets.private.secondary_ranges.gke_pods
services_secondary_range_name = local.subnets.private.secondary_ranges.gke_services
}
private_cluster_config {
enable_private_endpoint = false
enable_private_nodes = true
master_ipv4_cidr_block = "172.16.0.16/28"
}
addons_config {
http_load_balancing {
disabled = false
}
horizontal_pod_autoscaling {
disabled = false
}
network_policy_config {
disabled = false
}
dns_cache_config {
enabled = true
}
}
maintenance_policy {
daily_maintenance_window {
start_time = "02:00"
}
}
lifecycle {
prevent_destroy = true
}
timeouts {
create = "30m"
update = "30m"
delete = "30m"
}
}
resource "google_container_node_pool" "main" {
name = "${local.project_name}-main-node-pool"
cluster = google_container_cluster.this.name
location = data.google_client_config.this.zone
initial_node_count = 1
# autoscaling {
# max_node_count = 1
# min_node_count = 1
# }
management {
auto_repair = true
auto_upgrade = false
}
upgrade_settings {
max_surge = 1
max_unavailable = 0
}
node_config {
preemptible = false
machine_type = var.k8s.machine_type
disk_size_gb = 50
disk_type = "pd-standard"
local_ssd_count = 0
image_type = "COS"
service_account = google_service_account.kubernetes.email
metadata = {
disable-legacy-endpoints = "true"
}
tags = [
"web",
]
oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/devstorage.read_write",
]
}
lifecycle {
ignore_changes = [initial_node_count]
}
timeouts {
create = "30m"
update = "30m"
delete = "30m"
}
}
resource "kubernetes_storage_class" "pd-ssd" {
metadata {
name = "ssd"
}
storage_provisioner = "kubernetes.io/gce-pd"
reclaim_policy = "Retain"
parameters = {
type = "pd-ssd"
}
}