infrastructure/k8s.tjo.cloud/modules/cluster-core/monitoring.tf

131 lines
3.6 KiB
Terraform
Raw Normal View History

2024-07-26 21:40:38 +00:00
resource "kubernetes_namespace" "monitoring-system" {
metadata {
name = "monitoring-system"
2024-08-07 21:13:58 +00:00
labels = {
"pod-security.kubernetes.io/enforce" = "privileged"
}
2024-07-26 21:40:38 +00:00
}
}
resource "kubernetes_manifest" "prometheus-pod-monitors" {
2024-07-27 09:31:15 +00:00
manifest = yamldecode(file("${path.module}/manifests/crd-podmonitors.yaml"))
2024-07-26 21:40:38 +00:00
}
resource "kubernetes_manifest" "prometheus-service-monitors" {
2024-07-27 09:31:15 +00:00
manifest = yamldecode(file("${path.module}/manifests/crd-servicemonitors.yaml"))
}
resource "helm_release" "kube-state-metrics" {
depends_on = [kubernetes_manifest.prometheus-pod-monitors, kubernetes_manifest.prometheus-service-monitors]
name = "kube-state-metrics"
chart = "kube-state-metrics"
repository = "https://prometheus-community.github.io/helm-charts"
version = "5.24.0"
namespace = kubernetes_namespace.monitoring-system.metadata[0].name
atomic = true
cleanup_on_fail = true
values = [<<-EOF
nodeSelector:
node-role.kubernetes.io/control-plane: ""
tolerations:
- key: "node-role.kubernetes.io/control-plane"
2024-07-27 14:08:21 +00:00
effect: NoSchedule
updateStrategy: Recreate
prometheusScrape: false
2024-07-27 09:31:15 +00:00
prometheus:
monitor:
enabled: true
http:
honorLabels: true
EOF
]
2024-07-26 21:40:38 +00:00
}
2024-08-07 21:13:58 +00:00
resource "helm_release" "monitoring" {
2024-07-27 09:31:15 +00:00
depends_on = [kubernetes_manifest.prometheus-pod-monitors, kubernetes_manifest.prometheus-service-monitors]
2024-07-26 21:40:38 +00:00
2024-08-07 21:13:58 +00:00
name = "monitoring"
chart = "k8s-monitoring"
2024-07-26 21:40:38 +00:00
repository = "https://grafana.github.io/helm-charts"
2024-08-07 21:13:58 +00:00
version = "1.4.6"
2024-07-26 21:40:38 +00:00
namespace = kubernetes_namespace.monitoring-system.metadata[0].name
atomic = true
cleanup_on_fail = true
values = [<<-EOF
2024-08-07 21:13:58 +00:00
cluster:
name: "${var.cluster_name}"
2024-07-26 21:40:38 +00:00
2024-08-07 21:13:58 +00:00
prometheus-operator-crds:
enabled: false
prometheus-node-exporter:
enabled: true
kube-state-metrics:
enabled: false
opencost:
enabled: false
2024-07-26 21:40:38 +00:00
2024-08-07 21:13:58 +00:00
metrics:
enabled: true
serviceMonitors:
enabled: true
probes:
enabled: true
podMonitors:
enabled: true
node-exporter:
enabled: true
kubelet:
enabled: true
kube-state-metrics:
enabled: true
cost:
enabled: false
apiserver:
enabled: true
autoDiscover:
enabled: true
cadvisor:
enabled: true
kubeControllerManager:
enabled: true
kubeScheduler:
enabled: true
2024-07-26 21:40:38 +00:00
2024-08-07 21:13:58 +00:00
logs:
enabled: true
2024-07-26 21:40:38 +00:00
2024-08-07 21:13:58 +00:00
profiles:
enabled: false
receivers:
deployGrafanaAgentService: false
externalServices:
prometheus:
host: "https://prometheus.monitor.tjo.cloud"
writeEndpoint: "/api/v1/write"
authMode: "oauth2"
oauth2:
tokenURL: "https://id.tjo.space/application/o/token/"
clientId: "o6Tz2215HLvhvZ4RCZCR8oMmCapTu30iwkoMkz6m"
clientSecretFile: "/var/run/secrets/kubernetes.io/serviceaccount/token"
endpointParams:
grant_type: "client_credentials"
client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
loki:
host: "https://loki.monitor.tjo.cloud"
authMode: "oauth2"
oauth2:
tokenURL: "https://id.tjo.space/application/o/token/"
clientId: "56TYXtgg7QwLjh4lPl1PTu3C4iExOvO1d6b15WuC"
clientSecretFile: "/var/run/secrets/kubernetes.io/serviceaccount/token"
endpointParams:
grant_type: "client_credentials"
client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
2024-07-26 21:40:38 +00:00
EOF
]
}