In this lesson, you will learn how to use Pod Disruption Budgets (PDBs) to ensure your mission-critical .NET services remain highly available during planned cluster maintenance.
The Problem: Voluntary Disruptions
In a Kubernetes cluster, administrators often perform "voluntary" maintenance tasks, such as draining a node for OS patching, upgrading the control plane, or scaling down deployments. Without specific guardrails, Kubernetes might decide to evict all instances of your .NET service simultaneously, causing an unintended outage even if your code is perfectly written to handle graceful shutdowns.
The Solution: Pod Disruption Budgets
A Pod Disruption Budget acts as a safety contract between your application and the cluster orchestrator. It explicitly defines how many pods must remain running at any given time. By specifying minAvailable or maxUnavailable, you tell the Kubernetes scheduler that it cannot evict your pods if doing so would violate these thresholds.
For a mission-critical .NET microservice, you want to ensure at least one instance (or a percentage) is always available to handle incoming traffic:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: ordering-service-pdb
spec:
minAvailable: 1
selector:
matchLabels:
app: ordering-service
Why it Matters for .NET Services
Even if you have configured your Host to handle CancellationToken signals for graceful shutdown (as learned in our lesson on Graceful Shutdown Handling), the PDB is your final line of defense. It prevents the cluster from being "too efficient" during node maintenance. If the orchestrator tries to evict a pod and the PDB threshold is already met, the eviction request will be blocked until another pod becomes healthy and ready, ensuring that your ASP.NET Core middleware continues to serve requests without dropping connections.
Always verify your readiness probes are accurately reporting the health of your service; if your pods aren't marked as Ready, the PDB will block maintenance indefinitely to prevent service downtime.
Key Takeaway: Pod Disruption Budgets act as a safety buffer that prevents Kubernetes from taking down too many replicas of your .NET service during maintenance, ensuring continuous availability for your users.