-
Notifications
You must be signed in to change notification settings - Fork 7
/
k8s-scheduler-apiary.tf
162 lines (144 loc) · 5.11 KB
/
k8s-scheduler-apiary.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
/**
* Copyright (C) 2019-2021 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
locals {
scheduler_apiary_name = "scheduler-apiary"
scheduler_apiary_full_name = "${local.k8s_app_alias}-scheduler-apiary"
scheduler_apiary_labels = {
"app.kubernetes.io/name" = local.scheduler_apiary_full_name
"app.kubernetes.io/instance" = local.scheduler_apiary_full_name
"app.kubernetes.io/version" = var.scheduler_apiary_docker_image_version
"app.kubernetes.io/managed-by" = local.k8s_app_alias
}
scheduler_apiary_label_name_instance = {
"app.kubernetes.io/name" = local.scheduler_apiary_full_name
"app.kubernetes.io/instance" = local.scheduler_apiary_full_name
}
}
resource "kubernetes_deployment_v1" "beekeeper_scheduler_apiary" {
count = var.instance_type == "k8s" ? 1 : 0
metadata {
name = local.scheduler_apiary_full_name
namespace = var.k8s_namespace
labels = local.scheduler_apiary_labels
}
spec {
# setting the number of replicas to greater than 1 is currently untested
replicas = var.k8s_scheduler_apiary_replicas
selector {
match_labels = local.scheduler_apiary_label_name_instance
}
template {
metadata {
labels = local.scheduler_apiary_label_name_instance
annotations = {
"ad.datadoghq.com/${local.scheduler_apiary_full_name}.check_names": "[\"openmetrics\"]"
"ad.datadoghq.com/${local.scheduler_apiary_full_name}.init_configs": "[{}]"
"ad.datadoghq.com/${local.scheduler_apiary_full_name}.instances": "[{ \"prometheus_url\": \"http://%%host%%:8080/actuator/prometheus\", \"namespace\": \"${local.instance_alias}\", \"metrics\": [ \"${join("\",\"", var.beekeeper_scheduler_apiary_metrics)}\"] }]"
"prometheus.io/scrape" : var.prometheus_enabled
"prometheus.io/port" : var.k8s_scheduler_apiary_port
"prometheus.io/path" : "/actuator/prometheus"
}
}
spec {
service_account_name = kubernetes_service_account_v1.beekeeper_scheduler_apiary.metadata.0.name
automount_service_account_token = true
container {
name = local.scheduler_apiary_full_name
image = "${var.scheduler_apiary_docker_image}:${var.scheduler_apiary_docker_image_version}"
image_pull_policy = var.k8s_image_pull_policy
port {
container_port = var.k8s_scheduler_apiary_port
}
liveness_probe {
http_get {
path = "/actuator/health/liveness"
port = var.k8s_scheduler_apiary_port
}
initial_delay_seconds = var.k8s_scheduler_apiary_liveness_delay
}
resources {
limits = {
memory = var.k8s_scheduler_apiary_memory
cpu = var.k8s_scheduler_apiary_cpu
}
requests = {
memory = var.k8s_scheduler_apiary_memory
cpu = var.k8s_scheduler_apiary_cpu
}
}
env {
name = local.aws_region_key
value = var.aws_region
}
env {
name = local.aws_default_region_key
value = var.aws_region
}
env {
name = local.db_password_key
value_from {
secret_key_ref {
name = var.k8s_db_password_secret
key = local.db_password_key
}
}
}
env {
name = local.spring_application_json_key
value = data.template_file.beekeeper_scheduler_apiary_config.rendered
}
env {
name = "HADOOP_USER_NAME"
value = "beekeeper"
}
}
image_pull_secrets {
name = var.docker_registry_secret_name
}
}
}
}
}
resource "kubernetes_service" "beekeeper_scheduler_apiary" {
count = var.instance_type == "k8s" ? 1 : 0
metadata {
name = local.scheduler_apiary_full_name
labels = local.scheduler_apiary_labels
namespace = var.k8s_namespace
}
spec {
port {
name = local.scheduler_apiary_name
target_port = var.k8s_scheduler_apiary_port
port = var.k8s_scheduler_apiary_port
}
selector = local.scheduler_apiary_label_name_instance
type = "ClusterIP"
}
}
resource "kubernetes_service_account_v1" "beekeeper_scheduler_apiary" {
metadata {
name = local.scheduler_apiary_full_name
namespace = var.k8s_namespace
annotations = {
"eks.amazonaws.com/role-arn" = aws_iam_role.beekeeper_k8s_role_scheduler_apiary_iam[0].arn
}
}
}
resource "kubernetes_secret_v1" "beekeeper_scheduler_apiary" {
metadata {
name = local.scheduler_apiary_full_name
namespace = var.k8s_namespace
annotations = {
"kubernetes.io/service-account.name" = local.scheduler_apiary_full_name
"kubernetes.io/service-account.namespace" = var.k8s_namespace
}
}
type = "kubernetes.io/service-account-token"
depends_on = [
kubernetes_service_account_v1.beekeeper_scheduler_apiary
]
}