-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatefulset.tf
182 lines (154 loc) · 4.67 KB
/
statefulset.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
// ref: https://github.com/codecentric/helm-charts/blob/master/charts/keycloak/templates/statefulset.yaml
resource "kubernetes_stateful_set_v1" "keycloak" {
metadata {
name = var.name
namespace = var.namespace
}
spec {
replicas = var.autoscaling == null ? var.replicas : null
service_name = kubernetes_service_v1.headless.metadata[0].name
selector {
match_labels = local.selector_labels
}
template {
metadata {
labels = local.selector_labels
}
spec {
# image_pull_secrets {
# name = "some-secret-name"
# }
container {
name = var.name
image = var.image
# image_pull_policy = "Always"
port {
name = "http"
container_port = 8080
protocol = "TCP"
}
port {
name = "https"
container_port = 8443
protocol = "TCP"
}
port {
name = "http-management"
container_port = 9990
protocol = "TCP"
}
dynamic "volume_mount" {
for_each = local.startup_scripts.entries
iterator = each
content {
name = local.startup_scripts.volume_name
mount_path = "/opt/jboss/startup-scripts/${each.key}"
sub_path = each.key
read_only = true
}
}
resources {
limits = try(var.resources.limits, null)
requests = try(var.resources.requests, null)
}
startup_probe {
http_get {
path = "/health"
port = 9990
}
initial_delay_seconds = 60 # wait for a minute before the first probe (it is slow)
period_seconds = 20 # try every 20s
failure_threshold = 30 # try 30 times
}
liveness_probe {
http_get {
path = "/health"
port = 9990
}
}
dynamic "env" {
for_each = var.env
iterator = each
content {
name = each.key
value = each.value
}
}
env {
name = "PROXY_ADDRESS_FORWARDING"
value = "true"
}
env {
name = "JGROUPS_DISCOVERY_PROTOCOL"
value = "kubernetes.KUBE_PING"
}
env {
name = "KUBERNETES_NAMESPACE"
value = var.namespace
}
env {
name = "CACHE_OWNERS_COUNT"
value = "2"
}
env {
name = "CACHE_OWNERS_AUTH_SESSIONS_COUNT"
value = "2"
}
env {
# note: this enables the /metrics endpoint, it also makes the management endpoint bind to 0.0.0.0 thus allow probing the /health endpoint
# see: https://github.com/keycloak/keycloak-containers/blob/5df2de0500983e7424b321cca83a02c31da18fb3/server/tools/docker-entrypoint.sh#L94-L96
name = "KEYCLOAK_STATISTICS"
value = "all"
}
}
volume {
name = local.startup_scripts.volume_name
config_map {
name = kubernetes_config_map_v1.startup.metadata[0].name
default_mode = "0555" # 5 = rx
# dynamic "items" {
# for_each = local.startup_scripts.entries
# iterator = each
# content = {
# key = each.key
# path = each.key
# }
# }
}
}
dynamic "affinity" {
for_each = length(var.affinity_required_node_labels) > 0 ? [1] : []
content {
node_affinity {
required_during_scheduling_ignored_during_execution {
node_selector_term {
dynamic "match_expressions" {
for_each = toset(var.affinity_required_node_labels)
content {
key = match_expressions.key.key
operator = match_expressions.key.operator
values = match_expressions.key.values
}
}
}
}
}
}
}
}
}
}
}
resource "kubernetes_pod_disruption_budget_v1" "main" {
count = var.autoscaling != null || var.replicas > 1 ? 1 : 0
metadata {
name = var.name
namespace = var.namespace
}
spec {
min_available = 1
selector {
match_labels = local.selector_labels
}
}
}