forked from ExpediaGroup/apiary-federation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk8s.tf
205 lines (191 loc) · 5.25 KB
/
k8s.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* Copyright (C) 2018-2019 Expedia Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
locals {
heapsize = ceil((var.memory * 85) / 100)
memory_limit = ceil((var.memory * 120) / 100)
actuator_port = 18000
wd_port = 48869
k8s_cpu = var.cpu / 1024
k8s_cpu_limit = (var.cpu / 1024) * 1.25
}
resource "kubernetes_service_account" "waggle_dance" {
count = var.wd_instance_type == "k8s" ? 1 : 0
metadata {
name = local.instance_alias
namespace = var.k8s_namespace
annotations = {
"eks.amazonaws.com/role-arn" = var.oidc_provider == "" ? "" : aws_iam_role.waggle_dance_k8s_role_iam[0].arn
}
}
automount_service_account_token = true
}
resource "kubernetes_deployment" "waggle_dance" {
count = var.wd_instance_type == "k8s" ? 1 : 0
metadata {
name = local.instance_alias
namespace = var.k8s_namespace
labels = {
name = local.instance_alias
}
}
spec {
replicas = var.k8s_replica_count
selector {
match_labels = {
name = local.instance_alias
}
}
template {
metadata {
labels = {
name = local.instance_alias
}
annotations = {
"prometheus.io/scrape" : var.prometheus_enabled
"prometheus.io/port" : local.actuator_port
"prometheus.io/path" : "/actuator/prometheus"
}
}
spec {
service_account_name = kubernetes_service_account.waggle_dance[0].metadata.0.name
automount_service_account_token = true
container {
image = "${var.docker_image}:${var.docker_version}"
name = local.instance_alias
port {
container_port = local.wd_port
}
env {
name = "HEAPSIZE"
value = local.heapsize
}
env {
name = "LOGLEVEL"
value = var.wd_log_level
}
env {
name = "INVOCATIONLOGLEVEL"
value = var.enable_invocation_logs ? "debug" : "info"
}
env {
name = "SERVER_YAML"
value = base64encode(data.template_file.server_yaml.rendered)
}
env {
name = "FEDERATION_YAML"
value = base64encode(data.template_file.federation_yaml.rendered)
}
env {
name = "HIVE_SITE_XML"
value = var.alluxio_endpoints == [] ? "" : base64encode(data.template_file.hive_site_xml.rendered)
}
env {
name = "LOG4J_FORMAT_MSG_NO_LOOKUPS"
value = "true"
}
resources {
limits {
cpu = local.k8s_cpu_limit
memory = "${local.memory_limit}Mi"
}
requests {
cpu = local.k8s_cpu
memory = "${var.memory}Mi"
}
}
liveness_probe {
http_get {
path = "/actuator/health"
port = local.actuator_port
}
initial_delay_seconds = 60
period_seconds = 10
failure_threshold = 3
success_threshold = 1
}
}
image_pull_secrets {
name = var.k8s_docker_registry_secret
}
}
}
}
}
resource "kubernetes_horizontal_pod_autoscaler" "waggle_dance" {
count = var.wd_instance_type == "k8s" && var.enable_autoscaling ? 1 : 0
metadata {
name = local.instance_alias
namespace = var.k8s_namespace
}
spec {
min_replicas = var.k8s_replica_count
max_replicas = var.k8s_max_replica_count
target_cpu_utilization_percentage = var.wd_target_cpu_percentage
scale_target_ref {
api_version = "apps/v1"
kind = "Deployment"
name = kubernetes_deployment.waggle_dance[0].metadata[0].name
}
}
}
resource "kubernetes_service" "waggle_dance" {
count = var.wd_instance_type == "k8s" ? 1 : 0
metadata {
name = local.instance_alias
namespace = var.k8s_namespace
annotations = {
"service.beta.kubernetes.io/aws-load-balancer-internal" = "true"
"service.beta.kubernetes.io/aws-load-balancer-type" = "nlb"
}
}
spec {
selector = {
name = local.instance_alias
}
port {
port = local.wd_port
target_port = local.wd_port
}
type = "LoadBalancer"
load_balancer_source_ranges = var.ingress_cidr
}
}
resource "kubernetes_service" "waggle_dance_internal" {
count = var.wd_instance_type == "k8s" ? 1 : 0
metadata {
name = "${local.instance_alias}-internal"
namespace = var.k8s_namespace
}
spec {
selector = {
name = local.instance_alias
}
session_affinity = "ClientIP"
port {
port = local.wd_port
target_port = local.wd_port
}
type = "ClusterIP"
}
}
resource "kubernetes_service" "waggle_dance_headless" {
count = var.wd_instance_type == "k8s" ? 1 : 0
metadata {
name = "${local.instance_alias}-headless"
namespace = var.k8s_namespace
}
spec {
selector = {
name = local.instance_alias
}
port {
port = local.wd_port
target_port = local.wd_port
}
type = "ClusterIP"
cluster_ip = "None"
}
}