Reputation: 1086
I'm currently trying to add liveness
and readiness
endpoints to my service to deploy it on k8s.
I'm using the latest micronaut release (2.5.4), and having the following setup:
application.yml:
micronaut:
application:
name: sandbox
endpoints:
health:
enabled: true
sensitive: false
details-visible: ANONYMOUS
build.gradle:
plugins {
id("org.jetbrains.kotlin.jvm") version "1.4.32"
id("org.jetbrains.kotlin.kapt") version "1.4.32"
id("com.github.johnrengelman.shadow") version "7.0.0"
id("io.micronaut.application") version "1.5.0"
id("org.jetbrains.kotlin.plugin.allopen") version "1.4.32"
}
version = "0.1"
group = "com.example"
repositories {
mavenCentral()
}
micronaut {
runtime("netty")
testRuntime("junit5")
processing {
incremental(true)
annotations("com.example.*")
}
}
dependencies {
implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut:micronaut-management")
implementation("io.micronaut:micronaut-runtime")
implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("javax.annotation:javax.annotation-api")
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
runtimeOnly("ch.qos.logback:logback-classic")
implementation("io.micronaut:micronaut-validation")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
}
application {
mainClass.set("com.example.ApplicationKt")
}
java {
sourceCompatibility = JavaVersion.toVersion("11")
}
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
}
Whenever I'm hitting the endpoint localhost:8080/health/liveness
the response I'm getting is:
{"name":"sandbox","status":"UNKNOWN"}
However, when I'm calling localhost:8080/health/readiness
I'm getting correct response:
{"name":"sandbox","status":"UP","details":{"compositeDiscoveryClient()":{"name":"sandbox","status":"UP"},"diskSpace":{"name":"sandbox","status":"UP","details":{"total":499963174912,"free":384382533632,"threshold":10485760}},"service":{"name":"sandbox","status":"UP"}}}
It seems that I'm missing something but I couldn't find anything in Micronaut documentation about this...
Upvotes: 2
Views: 2366
Reputation: 2171
The current accepted answer will not report a status that reflects the real application status since you enforce your application to always return UP
no matter what error occurs within it.
The proper setup that should work is für your application.yaml
:
endpoints:
all:
# Expose all management endpoints on a different port. This allows us to control access
port: 8081
sensitive: false
info:
enabled: true
sensitive: false
health:
details-visible: ANONYMOUS
enabled: true
sensitive: false
and your k8s deployment
should be set properly e.g.
ports:
- name: management
containerPort: 8081
protocol: TCP
livenessProbe:
failureThreshold: 3
httpGet:
path: /health
port: 8081
initialDelaySeconds: 50
readinessProbe:
failureThreshold: 3
httpGet:
path: /info
port: 8081
initialDelaySeconds: 15
If this is not working, check your network policies
Upvotes: 5
Reputation: 1086
With the help in the comments, I've managed to solve the issue.
To make the liveness
work you need to add a Liveness implementation in form similar to the following:
@Singleton
@Liveness
class LivenessIndicator : HealthIndicator {
override fun getResult(): Publisher<HealthResult> =
Flowable.just(HealthResult.builder(LIVENESS_NAME).status(HealthStatus.UP).build())
companion object {
private const val LIVENESS_NAME = "liveness"
}
}
Upvotes: 1