Kubernetes probes and configuration
Kubernetes probes and configuration
Startup, liveness and readiness probes answer different questions about an application instance.
Startup allows initialization time before the recurring checks start. Liveness asks whether restarting an unhealthy process is appropriate; a transient database outage should not normally restart every healthy process. Readiness determines whether the instance should receive regular traffic; it can depend on required dependencies and local initialization. Failed readiness does not restart a container by itself. Use bounded checks and safe minimal response bodies. ASP.NET Core health-check tags and HealthCheckOptions.Predicate allow separate endpoint selection. The supplemental API implements separate /health/live and /health/ready endpoints with synthetic readiness state; it does not simulate an actual database. Kubernetes configuration belongs in ConfigMaps for nonsecret values and appropriately protected Secrets or external stores for credentials. Secret base64 is encoding, not encryption. A rollout should not rely on arbitrary sleeps. Use termination grace longer than the app's bounded shutdown budget, stop accepting new work and drain in-flight work with cancellation. Probe endpoints must not expose diagnostics or sensitive data publicly. Validate actual cluster admission, network policies, probes and restart behavior separately.
Baseline: .NET 10 / C# 14. All C# results below are reasoned, not executed. Synthetic calculations are not performance measurements.
Classify health states
Evaluate modeled process and dependency flags after startup.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits.
using System;foreach (var state in new[] { (Started:false, Alive:true, Dependency:false), (Started:true, Alive:true, Dependency:false), (Started:true, Alive:true, Dependency:true), (Started:true, Alive:false, Dependency:true) }) { bool ready = state.Started && state.Alive && state.Dependency; Console.WriteLine($"startup={state.Started}; live={state.Alive}; ready={ready}");}Expected result (not executed):
startup=False; live=True; ready=Falsestartup=True; live=True; ready=Falsestartup=True; live=True; ready=Truestartup=True; live=False; ready=FalseThe first line represents an internal state before startup passes; Kubernetes does not run the other probes until startup succeeds. A dependency outage alone should not trigger restart in this model.
Evaluate tagged ASP.NET Core health checks
Run health checks directly in a shared-framework console, without HTTP or real dependencies.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits. Requires the ASP.NET Core 10 shared framework.
using System;using System.Threading.Tasks;using System.Linq;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Diagnostics.HealthChecks;var services = new ServiceCollection();services.AddLogging();services.AddHealthChecks().AddCheck("process", () => HealthCheckResult.Healthy(), tags: new[]{"live"}) .AddCheck("dependency", () => HealthCheckResult.Unhealthy(), tags: new[]{"ready"});using var provider = services.BuildServiceProvider();var checks = provider.GetRequiredService<HealthCheckService>();foreach (string tag in new[]{"live", "ready"}) { var result = await checks.CheckHealthAsync(r => r.Tags.Contains(tag)); Console.WriteLine($"{tag}: {result.Status}");}Expected result (not executed):
live: Healthyready: UnhealthyThe underlying service evaluates selected checks; it does not prove HTTP mapping or Kubernetes behavior. Add endpoint integration tests for expected status codes.
Reserve a termination budget
A fictional grace period includes time for cleanup and a safety margin.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits.
using System;int graceSeconds = 30, shutdownSeconds = 20, marginSeconds = 5;Console.WriteLine(shutdownSeconds + marginSeconds <= graceSeconds ? "budget fits" : "budget too short");Console.WriteLine($"unallocated={graceSeconds-shutdownSeconds-marginSeconds}s");Expected result (not executed):
budget fitsunallocated=5sThis is a planning check, not a timing guarantee. Actual preStop hooks, connection draining and platform delays may consume the grace period.
Apply the concept
A process is healthy but its required database is down for 20 seconds. Choose probe outcomes and design a recovery test. Then explain how a 30-second termination budget should be checked.
Use the manual practice and knowledge check. Do not deploy or publish these fixtures.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Kubernetes probes and configuration — knowledge check
Apply the lesson concepts to the following scenarios.
What does failed readiness normally do?
What happens before startup succeeds?
Should transient DB outage always fail liveness?
What does a Secret base64 value guarantee?
What is required beyond a direct health-check test?