-
Notifications
You must be signed in to change notification settings - Fork 77
/
promtail.tf
204 lines (180 loc) · 6.17 KB
/
promtail.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
locals {
promtail = merge(
local.helm_defaults,
{
name = local.helm_dependencies[index(local.helm_dependencies.*.name, "promtail")].name
chart = local.helm_dependencies[index(local.helm_dependencies.*.name, "promtail")].name
repository = local.helm_dependencies[index(local.helm_dependencies.*.name, "promtail")].repository
chart_version = local.helm_dependencies[index(local.helm_dependencies.*.name, "promtail")].version
namespace = "monitoring"
create_ns = false
enabled = false
loki_address = "http://${local.loki-stack["name"]}-write:3100/loki/api/v1/push"
use_tls = false
tls_crt = null
tls_key = null
default_network_policy = false
},
var.promtail
)
values_promtail = <<-VALUES
priorityClassName: ${local.priority-class-ds["create"] ? kubernetes_priority_class.kubernetes_addons_ds[0].metadata[0].name : ""}
extraArgs:
- -client.external-labels=cluster=${var.cluster-name}
serviceMonitor:
enabled: ${local.kube-prometheus-stack["enabled"] || local.victoria-metrics-k8s-stack["enabled"]}
config:
clients:
- url: ${local.promtail["loki_address"]}
tolerations:
- effect: NoSchedule
operator: Exists
- key: CriticalAddonsOnly
operator: Exists
- effect: NoExecute
operator: Exists
VALUES
values_promtail_tls = <<-VALUES
defaultVolumes:
- name: run
hostPath:
path: /run/promtail
- name: containers
hostPath:
path: /var/lib/docker/containers
- name: pods
hostPath:
path: /var/log/pods
- name: tls
secret:
secretName: ${local.promtail["name"]}-tls
defaultVolumeMounts:
- name: run
mountPath: /run/promtail
- name: containers
mountPath: /var/lib/docker/containers
readOnly: true
- name: pods
mountPath: /var/log/pods
readOnly: true
- name: tls
mountPath: /tls
readOnly: true
config:
clients:
- url: ${local.promtail["loki_address"]}
tls_config:
cert_file: /tls/tls.crt
key_file: /tls/tls.key
VALUES
}
resource "kubernetes_namespace" "promtail" {
count = local.promtail["enabled"] && local.promtail["create_ns"] ? 1 : 0
metadata {
labels = {
name = local.promtail["namespace"]
"${local.labels_prefix}/component" = "monitoring"
}
name = local.promtail["namespace"]
}
}
resource "helm_release" "promtail" {
count = local.promtail["enabled"] ? 1 : 0
repository = local.promtail["repository"]
name = local.promtail["name"]
chart = local.promtail["chart"]
version = local.promtail["chart_version"]
timeout = local.promtail["timeout"]
force_update = local.promtail["force_update"]
recreate_pods = local.promtail["recreate_pods"]
wait = local.promtail["wait"]
atomic = local.promtail["atomic"]
cleanup_on_fail = local.promtail["cleanup_on_fail"]
dependency_update = local.promtail["dependency_update"]
disable_crd_hooks = local.promtail["disable_crd_hooks"]
disable_webhooks = local.promtail["disable_webhooks"]
render_subchart_notes = local.promtail["render_subchart_notes"]
replace = local.promtail["replace"]
reset_values = local.promtail["reset_values"]
reuse_values = local.promtail["reuse_values"]
skip_crds = local.promtail["skip_crds"]
verify = local.promtail["verify"]
values = compact([
local.values_promtail,
local.promtail["use_tls"] ? local.values_promtail_tls : "",
local.promtail["extra_values"]
])
namespace = local.promtail["namespace"]
depends_on = [
kubectl_manifest.prometheus-operator_crds,
helm_release.loki-stack,
kubernetes_secret.loki-stack-ca,
kubernetes_secret.promtail-tls
]
}
resource "kubernetes_secret" "promtail-tls" {
count = local.promtail["enabled"] && local.promtail["use_tls"] ? 1 : 0
metadata {
name = "${local.promtail["name"]}-tls"
namespace = local.promtail["namespace"]
}
type = "kubernetes.io/tls"
data = {
"tls.crt" = local.promtail["tls_crt"]
"tls.key" = local.promtail["tls_key"]
}
}
resource "kubernetes_network_policy" "promtail_default_deny" {
count = local.promtail["create_ns"] && local.promtail["enabled"] && local.promtail["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.promtail.*.metadata.0.name[count.index]}-default-deny"
namespace = kubernetes_namespace.promtail.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
policy_types = ["Ingress"]
}
}
resource "kubernetes_network_policy" "promtail_allow_namespace" {
count = local.promtail["create_ns"] && local.promtail["enabled"] && local.promtail["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.promtail.*.metadata.0.name[count.index]}-allow-namespace"
namespace = kubernetes_namespace.promtail.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
ingress {
from {
namespace_selector {
match_labels = {
name = kubernetes_namespace.promtail.*.metadata.0.name[count.index]
}
}
}
}
policy_types = ["Ingress"]
}
}
resource "kubernetes_network_policy" "promtail_allow_ingress" {
count = local.promtail["create_ns"] && local.promtail["enabled"] && local.promtail["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.promtail.*.metadata.0.name[count.index]}-allow-ingress"
namespace = kubernetes_namespace.promtail.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
ingress {
from {
namespace_selector {
match_labels = {
"${local.labels_prefix}/component" = "ingress"
}
}
}
}
policy_types = ["Ingress"]
}
}