-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubernetes-rakam-collector.tf
107 lines (98 loc) · 3.36 KB
/
kubernetes-rakam-collector.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
# Streamer to S3
resource "kubernetes_deployment" "rakam-collector" {
depends_on = ["kubernetes_namespace.rakam-api"]
metadata {
name = "rakam-collector"
namespace = "${kubernetes_namespace.rakam-api.metadata.0.name}"
labels = {
app = "rakam-collector"
}
}
spec {
replicas = var.rakam-collector-kinesis-shard-count
selector {
match_labels = {
app = "rakam-collector"
}
}
strategy {
type = "RollingUpdate"
}
template {
metadata {
name = "rakam-collector"
labels = {
app = "rakam-collector"
}
}
spec {
container {
name = "rakam-collector"
image = "${var.rakam-collector-container-image}"
image_pull_policy = "Always"
env_from {
secret_ref {
name = "${kubernetes_secret.rakam-collector-secret.metadata.0.name}"
}
}
env_from {
config_map_ref {
name = "${kubernetes_config_map.rakam-collector-config.metadata.0.name}"
}
}
command = ["java"]
# https://merikan.com/2019/04/jvm-in-a-container/
args = ["-Denv=RAKAM_CONFIG",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+ExitOnOutOfMemoryError",
"-XX:MinRAMPercentage=50.0",
"-XX:MaxRAMPercentage=80.0",
"-jar", "/compiled/target/rakam-data-collector.jar",
"/dev/null"] // instead of config.properties
resources {
limits {
memory = "${format("%.2fGi", var.instance-ram-in-gb * 0.45)}" // Limit maximum allocatable memory to half
}
requests {
memory = "${format("%.2fGi", var.instance-ram-in-gb * 0.45)}" // Request the half of allocatable memory
}
// Guaranteed memory for the collector
}
}
image_pull_secrets {
name = "${kubernetes_secret.gcr.metadata.0.name}"
}
restart_policy = "Always"
}
}
}
}
# Config maps & secrets
resource "kubernetes_config_map" "rakam-collector-config" {
metadata {
name = "rakamcollectorconfig"
namespace = "${kubernetes_namespace.rakam-api.metadata.0.name}"
}
data = { // TODO
RAKAM_CONFIG_TARGET = "s3"
RAKAM_CONFIG_TARGET_AWS_REGION = "${var.aws_region}"
RAKAM_CONFIG_TARGET_AWS_S3__BUCKET = "${aws_s3_bucket.rakams3.bucket}"
RAKAM_CONFIG_STREAM_SOURCE = "kinesis"
RAKAM_CONFIG_KINESIS_STREAM = "${aws_kinesis_stream.rakamstream.name}"
RAKAM_CONFIG_LICENSE_KEYNAME = "${var.rakam-collector-license-key-name}"
RAKAM_CONFIG_METADATA_STORE_JDBC_URL = "jdbc:mysql://${aws_db_instance.rakammysql.endpoint}/${aws_db_instance.rakammysql.name}?useSSL=false"
RAKAM_CONFIG_METADATA_STORE_JDBC_USERNAME = "${var.rakam-rds-username}"
RAKAM_CONFIG_METADATA_STORE_JDBC_MAX__CONNECTION = "5"
}
}
# Create secrets
resource "kubernetes_secret" "rakam-collector-secret" {
metadata {
name = "rakamcollectorsecret"
namespace = "${kubernetes_namespace.rakam-api.metadata.0.name}"
}
data = {
RAKAM_CONFIG_METADATA_STORE_JDBC_PASSWORD = "${var.rakam-rds-password}"
RAKAM_CONFIG_LICENSE_SERVICE__ACCOUNT__JSON = trimspace(file("${path.module}/license.json"))
}
}