Add service healthchecks

This commit is contained in:
IamTheFij 2024-01-23 12:08:47 -08:00
parent 0a2eace3dd
commit 35dfeb3093
6 changed files with 89 additions and 61 deletions

View File

@ -9,9 +9,11 @@ module "loki" {
service_port = 3100
ingress = true
use_wesher = var.use_wesher
service_check = {
path = "/ready"
}
sticky_disk = true
# healthcheck = "/ready"
templates = [
{
data = file("${path.module}/loki-config.yml")

View File

@ -53,6 +53,9 @@ job "traefik" {
sticky = true
}
task "traefik" {
driver = "docker"
service {
name = "traefik"
provider = "nomad"
@ -61,7 +64,6 @@ job "traefik" {
check {
type = "http"
path = "/ping"
port = "web"
interval = "10s"
timeout = "2s"
}
@ -73,15 +75,6 @@ job "traefik" {
]
}
task "traefik" {
driver = "docker"
meta = {
"diun.sort_tags" = "semver"
"diun.watch_repo" = true
"diun.include_tags" = "^[0-9]+\\.[0-9]+$"
}
config {
image = "traefik:2.10"

View File

@ -23,6 +23,9 @@ module "gitea" {
to = 22
}
]
service_check = {
path = "/api/healthz"
}
custom_services = [
{

View File

@ -15,6 +15,7 @@ resource "nomad_job" "service" {
service_port = var.service_port
service_port_static = var.service_port_static
service_check = var.service_check
ports = var.ports
sticky_disk = var.sticky_disk
resources = var.resources

View File

@ -73,6 +73,16 @@ job "${name}" {
source = "${host_volume.name}"
}
%{~ endfor ~}
task "${name}" {
driver = "docker"
%{~ if length(task_meta) > 0 }
meta = {
%{ for k, v in task_meta ~}
${k} = ${jsonencode(v)}
%{ endfor ~}
}
%{~ endif ~}
%{~ if service_port != null }
service {
name = "${replace(name, "_", "-")}"
@ -97,9 +107,24 @@ job "${name}" {
"${tag}",
%{~ endfor ~}
]
%{~ if service_check != null ~}
check {
%{~ if service_check.name != "" ~}
name = "${service_check.name}"
%{~ endif ~}
%{~ if service_check.name != "" ~}
port = "${service_check.port}"
%{~ endif ~}
type = "${service_check.type}"
path = "${service_check.path}"
interval = "${service_check.interval}"
timeout = "${service_check.timeout}"
}
%{~ endif ~}
}
%{~ endif ~}
%{~ for custom_service in custom_services ~}
service {
name = "${custom_service.name}"
@ -110,16 +135,6 @@ job "${name}" {
}
%{~ endfor ~}
task "${name}" {
driver = "docker"
%{~ if length(task_meta) > 0 }
meta = {
%{ for k, v in task_meta ~}
${k} = ${jsonencode(v)}
%{ endfor ~}
}
%{~ endif ~}
config {
image = "${image}"
%{~if image_pull_timeout != null ~}

View File

@ -268,3 +268,17 @@ variable "use_wesher" {
description = "Indicates whether or not services should expose themselves on the wesher network"
default = true
}
variable "service_check" {
description = "Health check for main ingress service"
type = object({
name = optional(string, "")
port = optional(string, "")
path = optional(string, "/")
interval = optional(string, "30s")
timeout = optional(string, "2s")
type = optional(string, "http")
})
default = {}
}