forked from ExpediaGroup/apiary-lifecycle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s-scheduler-apiary.tf
127 lines (113 loc) · 3.72 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
/**
* 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" "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 = 1
selector {
match_labels = local.scheduler_apiary_label_name_instance
}
template {
metadata {
labels = local.scheduler_apiary_label_name_instance
annotations = {
"iam.amazonaws.com/role" = aws_iam_role.beekeeper_k8s_role_scheduler_apiary_iam[count.index].arn
"prometheus.io/scrape" : var.prometheus_enabled
"prometheus.io/port" : var.k8s_scheduler_apiary_port
"prometheus.io/path" : "/actuator/prometheus"
}
}
spec {
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
}
}
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"
}
}