Configuration changes are a normal part of application deployment. Developers update database connection strings, API endpoints, authentication settings, feature flags, timeout values, and other application settings as requirements change.
However, a configuration change that looks correct in a deployment pipeline can still cause problems when the application starts inside Kubernetes.
For example, a new version of an ASP.NET Core application may contain an incorrect database connection string or a missing API key. The container can start, but the application may fail when it receives its first request.
During a rolling deployment, this creates a serious availability risk. Kubernetes gradually replaces existing Pods with new ones. If a new Pod is marked ready before its configuration has been validated, a Kubernetes Service may start sending requests to an application that cannot process them correctly.
The solution is to validate configuration during startup and use Kubernetes readiness probes to control when a Pod becomes available for traffic.
This approach allows a new Pod to remain outside normal Service traffic until the application has completed its required initialization. Combined with a carefully configured rolling update strategy, it helps prevent a bad configuration from affecting existing healthy instances.
Understand Why Configuration Errors Reach Production
Consider an ASP.NET Core application that connects to a database and an external payment service.
Its configuration might look like this:
{
"Database": {
"ConnectionString": "Server=db;Database=Orders;User Id=app;Password=secret;"
},
"Payment": {
"BaseUrl": "https://payments.example.com",
"ApiKey": "configured-api-key"
}
}
Now imagine that a deployment changes the payment endpoint to an invalid URL or removes the API key.
The application may still start because configuration values are not necessarily validated when the configuration file is loaded.
The error may appear only when the application tries to initialize a payment client or process its first payment request.
This creates several possible problems:
Requests fail after reaching the new Pod.
The application repeatedly fails when accessing an external service.
Existing healthy Pods receive additional traffic.
The deployment may appear successful even though the new version cannot perform its required operations.
A better design checks required configuration before the application becomes available.
There are two important responsibilities:
The application validates whether its configuration is valid.
Kubernetes determines whether the application is ready to receive traffic.
Both responsibilities are necessary because Kubernetes does not understand the business meaning of an application's configuration values.
Validate Application Configuration During Startup
ASP.NET Core provides the Options pattern for organizing and validating application settings.
Instead of reading configuration values directly throughout the application, define strongly typed configuration classes.
For example:
using System.ComponentModel.DataAnnotations;
public sealed class PaymentOptions
{
public const string SectionName = "Payment";
[Required]
[Url]
public string BaseUrl { get; set; } = string.Empty;
[Required]
public string ApiKey { get; set; } = string.Empty;
[Range(1, 60)]
public int TimeoutSeconds { get; set; }
}
This class defines the expected payment configuration.
The validation attributes check that required values are present and that the timeout falls within an acceptable range.
Register the configuration in Program.cs:
builder.Services
.AddOptions<PaymentOptions>()
.Bind(builder.Configuration.GetSection(
PaymentOptions.SectionName))
.ValidateDataAnnotations()
.Validate(
options =>
Uri.TryCreate(
options.BaseUrl,
UriKind.Absolute,
out var uri)
&& uri.Scheme == Uri.UriSchemeHttps,
"Payment BaseUrl must use HTTPS.")
.ValidateOnStart();
The important method here is ValidateOnStart().
Without startup validation, options validation generally occurs when the options instance is first accessed. That might happen during request processing.
With ValidateOnStart(), the application validates the registered options during host startup.
If required configuration is missing or invalid, startup fails instead of allowing the application to continue with an invalid configuration.
This is particularly useful for database settings, external service endpoints, authentication configuration, and other values that are essential for application operation.
Separate Configuration Validation From Dependency Health
A valid configuration does not guarantee that every external service is available.
For example, a database connection string may have the correct format, but the database server may be temporarily unavailable.
These are two different conditions.
Configuration validation checks whether the application has acceptable settings.
Readiness checks determine whether the running application can currently serve requests.
Consider the following examples:
Condition | Configuration validation | Readiness check |
|---|
Missing database connection string | Fail | Application should not become ready |
Invalid payment endpoint | Fail | Application should not become ready |
Database temporarily unavailable | Configuration may be valid | Not ready if database access is essential |
Required cache still initializing | Configuration may be valid | Not ready until initialization completes |
Application fully initialized | Pass | Ready when other required checks also pass |
Avoid using a readiness endpoint as the only place to discover missing static configuration. Validate those values during startup so the application fails early and provides a clear error.
Readiness checks are more appropriate for conditions that can change while the application is running.
Create Separate Readiness and Liveness Endpoints
ASP.NET Core provides health check middleware that can expose application health through HTTP endpoints.
Register the health checks:
builder.Services.AddHealthChecks();
Then map separate endpoints:
app.MapHealthChecks("/health/live");
app.MapHealthChecks("/health/ready");
This is a basic example. In a production application, readiness should include the checks required to determine whether the application can serve its intended requests.
For example, a custom database health check can be registered with a readiness tag:
builder.Services
.AddHealthChecks()
.AddCheck<DatabaseHealthCheck>(
"Database",
tags: new[] { "ready" });
Then configure the readiness endpoint to execute only the relevant checks:
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
app.MapHealthChecks(
"/health/ready",
new HealthCheckOptions
{
Predicate = check =>
check.Tags.Contains("ready")
});
app.MapHealthChecks(
"/health/live",
new HealthCheckOptions
{
Predicate = _ => false
});
The liveness endpoint checks whether the application process can respond.
The readiness endpoint checks whether the application has the required capabilities to accept normal requests.
For a production application, add appropriate checks for required dependencies and initialization state.
Do not make every optional dependency a readiness requirement. If a nonessential reporting service is temporarily unavailable, it should not necessarily prevent the entire API from serving requests.
Configure Kubernetes Readiness and Startup Probes
Once the application exposes health endpoints, Kubernetes can use them to control Pod availability.
Consider this Pod configuration:
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-api
spec:
replicas: 3
selector:
matchLabels:
app: order-api
template:
metadata:
labels:
app: order-api
spec:
containers:
- name: order-api
image: mycompany/order-api:latest
ports:
- containerPort: 8080
startupProbe:
httpGet:
path: /health/live
port: 8080
periodSeconds: 10
failureThreshold: 30
readinessProbe:
httpGet:
path: /health/ready
port: 8080
periodSeconds: 5
timeoutSeconds: 2
failureThreshold: 3
successThreshold: 1
livenessProbe:
httpGet:
path: /health/live
port: 8080
periodSeconds: 15
timeoutSeconds: 2
failureThreshold: 3
Each probe has a different responsibility.
The startup probe allows the application time to initialize. Kubernetes does not execute the readiness and liveness probes until the startup probe succeeds.
The readiness probe determines whether the Pod can receive traffic. If it fails, Kubernetes marks the Pod as not ready and removes it from the ready endpoints used by matching Services.
The liveness probe determines whether the container should be restarted because the application is no longer functioning correctly.
An important detail is that a startup probe does not validate application configuration by itself. It only checks whether the application has reached the condition represented by its configured endpoint.
If the application fails startup because ValidateOnStart detects invalid settings, the HTTP endpoint will not become available. Kubernetes will therefore not mark the Pod ready.
Protect Existing Pods During a Rolling Deployment
Readiness probes become especially important when combined with the Deployment rolling update strategy.
Consider a Deployment with three replicas.
The existing Pods are running correctly, and a new version is released with an incorrect configuration.
Without appropriate rollout settings, Kubernetes may make existing Pods unavailable while attempting to replace them.
To reduce this risk, configure maxUnavailable and maxSurge:
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-api
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
minReadySeconds: 10
progressDeadlineSeconds: 300
selector:
matchLabels:
app: order-api
template:
metadata:
labels:
app: order-api
spec:
containers:
- name: order-api
image: mycompany/order-api:v2
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /health/ready
port: 8080
periodSeconds: 5
Here is what these settings achieve:
Setting | Purpose |
|---|
replicas: 3 | Maintains three desired application replicas |
maxUnavailable: 0 | Prevents the rolling update from intentionally reducing available replicas below the desired count |
maxSurge: 1 | Allows one additional Pod during the update |
minReadySeconds: 10 | Requires a Pod to remain ready for the specified period before it is considered available |
progressDeadlineSeconds: 300 | Marks the Deployment as stalled if it does not make sufficient progress within the configured period |
Suppose the first new Pod starts with an invalid payment configuration.
The startup validation fails, or the readiness probe continues returning an unsuccessful response.
The new Pod does not become available through the Service.
Because maxUnavailable is zero, the Deployment does not intentionally remove an available old replica to make room for an unavailable replacement.
The rollout therefore stops making progress while existing healthy Pods continue serving traffic.
This is an important protection against configuration-related deployment failures.
However, Kubernetes does not automatically roll back a Deployment merely because its progress deadline is exceeded. It reports the stalled rollout, and the deployment pipeline or an operator must decide whether to roll back.
Handle Configuration Changes Consistently
Another problem appears when configuration is stored in ConfigMaps or Secrets.
A Deployment may reference a ConfigMap through environment variables:
env:
- name: PAYMENT_API_URL
valueFrom:
configMapKeyRef:
name: payment-settings
key: api-url
Updating the ConfigMap does not automatically restart existing Pods that consume its values as environment variables.
A new Pod receives the updated configuration when it starts, but an existing Pod continues using its original environment.
This can create inconsistent behavior during a deployment.
A useful approach is to version configuration changes or include a configuration checksum in the Pod template metadata.
For example:
spec:
template:
metadata:
annotations:
config-version: "payment-settings-v2"
When the annotation changes, the Pod template changes and Kubernetes creates a new ReplicaSet.
In a Helm-based deployment, a checksum of the relevant ConfigMap or Secret template can be used instead of manually changing a version string.
This ensures that configuration changes participate in the same controlled rollout as application changes.
For Secrets, avoid placing actual secret values in annotations or deployment logs. Use a checksum or version identifier that does not expose sensitive content.
Detect and Investigate a Failed Configuration Rollout
A failed rollout should be visible to the deployment pipeline and operations team.
Start by checking the rollout status:
kubectl rollout status deployment/order-api
Inspect the Deployment:
kubectl describe deployment order-api
Check the Pods:
kubectl get pods -l app=order-api
For a Pod that is not becoming ready:
kubectl describe pod <pod-name>
Inspect its logs:
kubectl logs <pod-name>
If the container has restarted, previous logs may also be available:
kubectl logs <pod-name> --previous
For an invalid configuration, the application logs should identify the relevant validation failure without exposing passwords, tokens, or connection-string secrets.
The deployment pipeline should treat a failed rollout as a failed release rather than reporting success simply because the image was pushed or the Pods were created.
If necessary, restore the previous version:
kubectl rollout undo deployment/order-api
After rollback, verify that the previous healthy version is available again.
Common Mistakes to Avoid
Mistake | Why it causes problems | Better approach |
|---|
Validating configuration only during the first request | The Pod may receive traffic before the error appears | Use startup validation |
Using only a liveness probe | A running process may still be unable to serve requests | Configure readiness separately |
Treating readiness and liveness as identical | Temporary dependency problems may trigger unnecessary restarts | Give each probe a clear responsibility |
Setting maxUnavailable above zero without considering capacity | Healthy replicas may be removed during a failed rollout | Use an appropriate availability strategy |
Assuming Kubernetes automatically rolls back failed deployments | A stalled rollout is reported but not automatically reverted | Integrate rollout monitoring and rollback into deployment automation |
Putting secrets in configuration annotations | Sensitive values can leak through metadata | Use secret references and safe version identifiers |
Checking every external dependency on every probe | Expensive checks can overload dependencies | Use lightweight, targeted health checks |
Best Practices for Production Applications
Use strongly typed configuration classes for important application settings.
Validate required values, formats, ranges, and security requirements during startup.
Use ValidateOnStart() so invalid configuration is detected before normal request processing begins.
Keep liveness and readiness endpoints separate.
Include only essential dependencies in readiness checks.
Configure startup probes for applications that need additional initialization time.
Use maxUnavailable: 0 and an appropriate maxSurge value when maintaining existing capacity during configuration-sensitive rollouts.
Use configuration versioning or checksums to ensure that configuration changes trigger controlled Pod replacement.
Monitor rollout status and configure the deployment pipeline to detect stalled releases.
Test deployments with deliberately invalid configuration to verify that new Pods never become ready and existing healthy Pods remain available.
Summary
A configuration error should be detected before a new Kubernetes Pod receives production traffic.
ASP.NET Core provides startup configuration validation through the Options pattern and ValidateOnStart(). Kubernetes readiness probes then determine whether a Pod is eligible to receive traffic through a Service.
The rolling update strategy provides another layer of protection. Settings such as maxUnavailable, maxSurge, and minReadySeconds help maintain existing availability while new Pods are evaluated.
The important point is that creating a Pod does not mean the application is ready. Configuration must be valid, required initialization must complete, and the readiness check must succeed before the new instance becomes available.
By combining application-level validation, Kubernetes health probes, controlled rolling updates, and deployment monitoring, teams can detect bad configuration changes early without unnecessarily disrupting healthy production instances.
Join the conversation! Your thoughts help the community grow.