
The true test of an engineering organization's cloud architecture is whether it can deploy a new release at peak traffic without returning a single 502 Bad Gateway or interrupting an active checkout transaction. In this guide, we examine the complete directory layout and production configuration files for **Zero-Downtime CI/CD** across Docker, Kubernetes, .NET 9, and Nginx.
What You Will Master in This Guide:
1. Complete DevOps directory structure (Dockerfile.api,deploy/k8s/,deploy/nginx/,.github/workflows/).
2. Hardened Multi-Stage Alpine Dockerfiles running as non-root users.
3. ASP.NET Core Health Check endpoints (/health/readyvs./health/live) and SIGTERM graceful draining.
4. KubernetesRollingUpdatewithmaxUnavailable: 0,readinessProbe, andpreStoplifecycle hooks.
5. Nginx upstream keepalive and zero-drop reverse proxy configuration.
1. Production DevOps & Deployment Directory Tree
DigitalHat.Platform/
├── Dockerfile.api # Multi-stage .NET 9 Alpine build
├── Dockerfile.web # Next.js Standalone build
├── .github/workflows/
│ └── deploy-production.yml # Automated Test -> Build -> Rollout pipeline
└── deploy/
├── nginx/dgtalhat.conf # TLS 1.3 & Upstream Keepalive reverse proxy
└── k8s/
├── api-deployment.yaml # Zero-downtime RollingUpdate & Health Probes
└── api-service.yaml
2. Hardened Multi-Stage .NET 9 Dockerfile.api
# Stage 1: Build
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
WORKDIR /src
COPY ["src/DigitalHat.Api/DigitalHat.Api.csproj", "src/DigitalHat.Api/"]
RUN dotnet restore "src/DigitalHat.Api/DigitalHat.Api.csproj"
COPY . .
RUN dotnet publish "src/DigitalHat.Api/DigitalHat.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false
# Stage 2: Minimal Non-Root Runtime (~105 MB)
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine AS runtime
WORKDIR /app
USER $APP_UID
COPY --from=build /app/publish .
ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080
ENTRYPOINT ["dotnet", "DigitalHat.Api.dll"]
3. Kubernetes Zero-Downtime api-deployment.yaml
To guarantee zero dropped packets during a rollout, we combine three mechanisms: maxUnavailable: 0 (never terminate an old pod before a new pod is ready), readinessProbe (verify database connectivity before routing traffic), and a 5-second preStop hook so kube-proxy and Nginx finish draining in-flight requests before Kestrel receives SIGTERM:
apiVersion: apps/v1
kind: Deployment
metadata:
name: digitalhat-api
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: digitalhat-api
template:
metadata:
labels:
app: digitalhat-api
spec:
terminationGracePeriodSeconds: 30
containers:
- name: api
image: registry.dgtalhat.com/digitalhat-api:v2.4.0
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /health/ready
port: 8080
initialDelaySeconds: 3
periodSeconds: 5
livenessProbe:
httpGet:
path: /health/live
port: 8080
initialDelaySeconds: 10
periodSeconds: 15
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 5"]
4. ASP.NET Core Readiness & Graceful Shutdown Configuration
// File: src/DigitalHat.Api/Program.cs
var builder = WebApplication.CreateBuilder(args);
// Give in-flight HTTP requests 25 seconds to finish after SIGTERM arrives:
builder.Services.Configure<HostOptions>(options =>
{
options.ShutdownTimeout = TimeSpan.FromSeconds(25);
});
builder.Services.AddHealthChecks()
.AddDbContextCheck<AppDbContext>(tags: new[] { "ready" });
var app = builder.Build();
app.MapHealthChecks("/health/live", new HealthCheckOptions { Predicate = _ => false });
app.MapHealthChecks("/health/ready", new HealthCheckOptions { Predicate = check => check.Tags.Contains("ready") });
app.MapControllers();
app.Run();
Did you find this engineering guide helpful?
Give it a like or share it with your team and network.