-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgke.tf
133 lines (109 loc) · 2.78 KB
/
gke.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
resource "google_service_account" "gke-sa" {
account_id = "${var.cluster_name}-gke-sa"
display_name = "GKE TF Service Account"
}
resource "google_container_cluster" "gke" {
name = var.cluster_name
location = var.zone
initial_node_count = 3
deletion_protection = false
datapath_provider = "ADVANCED_DATAPATH"
node_config {
machine_type = var.machine_type
disk_size_gb = 40
image_type = "COS_CONTAINERD"
disk_type = "pd-balanced"
oauth_scopes = [
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/trace.append"
]
service_account = google_service_account.gke-sa.email
metadata = {
disable-legacy-endpoints = "true"
}
}
logging_config {
enable_components = ["WORKLOADS"]
}
monitoring_config {
enable_components = [
"SYSTEM_COMPONENTS",
"STORAGE",
"POD",
"DEPLOYMENT",
"STATEFULSET",
"DAEMONSET",
"HPA",
"CADVISOR",
"KUBELET"
]
}
control_plane_endpoints_config {
dns_endpoint_config {
allow_external_traffic = true
}
}
addons_config {
gcp_filestore_csi_driver_config {
enabled = true
}
}
private_cluster_config {
enable_private_nodes = true
}
default_snat_status {
disabled = true
}
networking_mode = "VPC_NATIVE"
network = google_compute_network.vpc.name
subnetwork = google_compute_subnetwork.subnet.name
}
resource "kubernetes_namespace" "chat-stack" {
depends_on = [google_container_cluster.gke]
metadata {
name = "chat-stack"
}
}
resource "kubernetes_namespace" "nginx" {
depends_on = [google_container_cluster.gke]
metadata {
name = "nginx"
}
}
resource "kubernetes_storage_class" "filestore_vpc" {
metadata {
name = "standard-rwx-vpc"
}
storage_provisioner = "filestore.csi.storage.gke.io"
parameters = {
network = "projects/${var.project_id}/global/networks/${google_compute_network.vpc.name}"
tier = "standard"
}
allow_volume_expansion = true
}
resource "kubernetes_persistent_volume_claim" "pvc" {
metadata {
name = "chat-stack-pvc"
namespace = kubernetes_namespace.chat-stack.metadata[0].name
}
timeouts {
create = "5m"
}
wait_until_bound = false
spec {
access_modes = ["ReadWriteMany"]
storage_class_name = kubernetes_storage_class.filestore_vpc.metadata[0].name
resources {
requests = {
storage = "200Gi"
}
}
}
}
output "cluster_name" {
value = google_container_cluster.gke.name
}