-
Notifications
You must be signed in to change notification settings - Fork 7
/
k8s-api.tf
155 lines (137 loc) · 3.73 KB
/
k8s-api.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
/**
* Copyright (C) 2019-2021 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
locals {
api_name = "api"
api_full_name = "${local.k8s_app_alias}-api"
api_labels = {
"app.kubernetes.io/name" = local.api_full_name
"app.kubernetes.io/instance" = local.api_full_name
"app.kubernetes.io/version" = var.api_docker_image_version
"app.kubernetes.io/managed-by" = local.k8s_app_alias
}
api_label_name_instance = {
"app.kubernetes.io/name" = local.api_full_name
"app.kubernetes.io/instance" = local.api_full_name
}
}
resource "kubernetes_deployment_v1" "beekeeper_api" {
count = var.instance_type == "k8s" ? 1 : 0
metadata {
name = local.api_full_name
namespace = var.k8s_namespace
labels = local.api_labels
}
spec {
# setting the number of replicas to greater than 1 is currently untested
replicas = 1
selector {
match_labels = local.api_label_name_instance
}
template {
metadata {
labels = local.api_label_name_instance
annotations = {
"prometheus.io/scrape" : var.prometheus_enabled
"prometheus.io/port" : var.k8s_beekeeper_api_port
"prometheus.io/path" : "/actuator/prometheus"
}
}
spec {
container {
name = local.api_full_name
image = "${var.api_docker_image}:${var.api_docker_image_version}"
image_pull_policy = var.k8s_image_pull_policy
port {
container_port = var.k8s_beekeeper_api_port
}
liveness_probe {
http_get {
path = "/actuator/health"
port = var.k8s_beekeeper_api_port
}
failure_threshold = 11
initial_delay_seconds = 60
period_seconds = 30
}
resources {
limits = {
memory = var.k8s_api_memory
cpu = var.k8s_api_cpu
}
requests = {
memory = var.k8s_api_memory
cpu = var.k8s_api_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_api_config.rendered
}
}
image_pull_secrets {
name = var.docker_registry_secret_name
}
}
}
}
}
resource "kubernetes_service" "beekeeper_api" {
count = var.instance_type == "k8s" ? 1 : 0
metadata {
name = local.api_full_name
labels = local.api_labels
namespace = var.k8s_namespace
}
spec {
port {
target_port = var.k8s_beekeeper_api_port
port = var.k8s_beekeeper_api_port
}
selector = local.api_label_name_instance
type = "ClusterIP"
}
}
resource "kubernetes_ingress_v1" "beekeeper-api" {
metadata {
name = local.api_full_name
namespace = var.k8s_namespace
}
spec {
rule {
host = "${local.api_full_name}.${local.dnsname}.${local.dnsdomain}"
http {
path {
backend {
service {
name = local.api_full_name
port {
number = var.k8s_beekeeper_api_port
}
}
}
path = "/"
}
}
}
}
}