What a container actually is
A container is not a small virtual machine. It is a normal process on the host kernel, with its view of the world restricted — its own filesystem, network and process tree, and a ceiling on how much CPU and memory it may use.
Which explains several things that confuse people the first time:
- There is no boot. A container starts as fast as a process starts, because that is all it is.
- The kernel is shared. Windows containers need a Windows host; Linux containers need a Linux one. There is no magic layer in between.
- PID 1 is your process, which means signal handling is yours. A process that ignores a termination signal gets killed hard after the grace period, mid-request.
- The filesystem vanishes when the container does. Anything written inside it and not on a mounted volume is gone.
Images: smaller, and not running as root
An image is a stack of read-only layers. Each instruction in the build adds one, and layers are cached by content — which is the whole basis of a fast build.
# Build in one image, ship from a smaller one.
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
# Restore before copying the source: dependencies change far less
# often than code, so this layer stays cached across most builds.
COPY *.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /app
# The runtime image carries no compiler and no source.
FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY --from=build /app .
USER $APP_UID
ENTRYPOINT ["dotnet", "MyApi.dll"]
Three habits that pay for themselves:
- Copy the dependency manifest before the source. It is the single biggest build speed win and the one most often missed.
- Multi-stage, always. The build tools are an attack surface you do not need to ship and do not want to pay to store.
- Do not run as root. It costs one line. A container escape from a root process is a much worse day than one from an unprivileged one.
The Kubernetes objects you need
Kubernetes has a large API. A normal web service needs five objects, and you can go a long way before needing a sixth.
The mental model worth holding: Pods are cattle. They are created, killed and replaced constantly — by a deploy, by a node being drained, by an autoscaler. Anything your app keeps in memory and cares about will be lost, without warning, at an inconvenient moment. Sessions belong in a shared cache; files belong in object storage.
Probes: the two that are not the same
This is the single most common misconfiguration I see, and it causes outages that look like everything else.
| Readiness | Liveness | |
|---|---|---|
| Question | Can I serve traffic right now? | Am I broken beyond recovery? |
| On failure | Removed from the load balancer; keeps running | Killed and restarted |
| Should check | Dependencies needed to serve, warm-up complete | Almost nothing — just that the process responds |
readinessProbe:
httpGet: { path: /health/ready, port: 8080 }
periodSeconds: 5
livenessProbe:
httpGet: { path: /health/live, port: 8080 } # returns 200 if the process is up
periodSeconds: 20
failureThreshold: 3
startupProbe:
httpGet: { path: /health/live, port: 8080 } # slow start without a loose liveness probe
failureThreshold: 30
periodSeconds: 5
Requests and limits
Two numbers with very different consequences. Requests are what the scheduler reserves — they decide where a pod lands. Limits are the ceiling, and the two resources behave completely differently at that ceiling:
- Over the CPU limit: throttled. The app gets slow. Nothing crashes, nothing logs an error, and the symptom looks like a performance problem rather than a configuration one.
- Over the memory limit: killed. Immediately, with no grace period and no chance to finish the current request. You see the exit code and nothing else.
Deploying without dropping requests
A rolling update replaces pods gradually, which only works if the app participates. The sequence when a pod is told to stop:
The fixes are small and specific:
- Handle SIGTERM and stop accepting new work while finishing what is in flight.
Most modern web frameworks do this if you let them shut down gracefully instead of calling
Environment.Exit. - Add a short
preStopsleep — a few seconds. Endpoint removal propagates asynchronously, so without it a proxy can still send you a request after you have begun shutting down. - Set a termination grace period longer than your slowest reasonable request.
- Add a PodDisruptionBudget so voluntary disruptions — node upgrades, scale-downs — cannot take every replica at once.
Choosing an Azure service
The main skill here is not using Kubernetes. Pick the least capable service that does the job, and move up only when you hit a wall you can name.
| Service | Good for | You give up |
|---|---|---|
| App Service | A web app or API with predictable shape. Deploy slots, autoscale and TLS are built in, and there is no cluster to run. | Fine-grained control over networking and scheduling. |
| Container Apps | Containers and background workers without a cluster. Scales on HTTP traffic or queue depth, including to zero. This is the sweet spot for most microservice work. | Direct access to the Kubernetes API and custom operators. |
| Functions | Event-driven, short-lived, bursty work. Pay for execution rather than uptime. | Long-running processes, and a cold-start tax on latency-sensitive paths. |
| AKS | Many services, a platform team, real need for custom networking, operators or node-level control. | Weekends. A cluster is a product you now own, upgrade and secure. |
The thread running through all of this: containers made deployment boring, and the orchestration layer exists to keep it boring. Every feature you adopt is a thing you maintain. The teams I have seen running comfortably use a small, well-understood subset and spend their attention on the application instead.