Managing Kubernetes in production taught me that the gap between a working deployment and a reliable one comes down to seven specific patterns. Miss any of these and you'll fight mysterious pod failures, resource starvation, or silent security holes.
I've rebuilt enough broken clusters to recognize the patterns that actually matter versus the ones that just sound good in documentation.
Use resource requests and limits on every container
Kubernetes can't schedule pods intelligently if it doesn't know what they need. Resource requests tell the scheduler how much CPU and memory a pod requires to start. Limits cap what it can actually consume.
Without requests, your scheduler makes blind guesses. A memory-hungry pod might land on a node that's already tight, causing OOM kills across unrelated workloads. Without limits, a single runaway container can starve everything else on the node.
Here's a basic example:
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
Set requests based on steady-state usage, not peak. Limits should be your genuine ceiling—the point where killing the pod is better than letting it continue. If you set limits too low, you'll see throttling and restarts. Too high and you waste capacity.
For CPU, throttling happens when you hit the limit but the pod keeps running. For memory, hitting the limit triggers an OOM kill. Keep that difference in mind when tuning.
Implement proper liveness and readiness probes
Probes tell Kubernetes whether your container is alive and ready to serve traffic. Without them, a crashed application can sit behind a service endpoint indefinitely, returning errors to users while the control plane thinks everything is fine.
Liveness probes detect when a container is stuck or deadlocked. If the probe fails repeatedly, Kubernetes restarts the container. Readiness probes determine if a pod should receive traffic. A failing readiness probe removes the pod from service endpoints without killing it.
Don't use the same probe for both. A long startup time shouldn't trigger a restart, so your liveness probe needs a longer failure threshold than readiness.
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
failureThreshold: 2
Your health endpoints should be cheap to execute. I've seen probes that queried databases or called external APIs, which introduced cascading failures when those dependencies slowed down. Check internal state only.
Startup probes exist for containers with long initialization times. They disable liveness checks until the first successful probe, preventing premature restarts during boot.
Configure pod disruption budgets for critical services
Pod Disruption Budgets (PDBs) protect your application during voluntary disruptions like node drains, cluster upgrades, or autoscaler adjustments. Without a PDB, Kubernetes might evict all replicas of a service simultaneously during maintenance.
A PDB specifies either the minimum number of pods that must remain available or the maximum that can be unavailable at once:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: api-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: api
For stateless services, maxUnavailable: 1 works well—it allows rolling operations while keeping most capacity online. For stateful workloads or small replica counts, minAvailable gives you direct control.
PDBs don't prevent involuntary disruptions like node failures or OOM kills. They only gate operations initiated through the eviction API. That's still valuable because it stops your own maintenance from causing outages.
Use deployment strategies that match your application
The default RollingUpdate strategy works for most stateless apps, but it's not the only option and it's not always the right one.
RollingUpdate gradually replaces old pods with new ones. The maxUnavailable and maxSurge parameters control how aggressive the rollout is:
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
Setting maxUnavailable: 0 ensures you never drop below desired capacity. maxSurge: 1 adds one extra pod during updates, so you need headroom on your nodes.
Recreate strategy tears down all old pods before creating new ones. You get downtime, but you also get a clean cutover. Use it when you can't run old and new versions side-by-side—schema migrations that aren't backward-compatible, file lock conflicts, or licensing restrictions.
For more control, look at blue-green or canary patterns using tools like Argo Rollouts or Flagger. These aren't native Kubernetes features but they integrate cleanly and give you traffic splitting, automated rollbacks, and metric-based promotion.
Set appropriate security contexts
Running containers as root is the default and it's also the worst default. A compromised container with root access can potentially escape to the host or pivot to other pods.
Security contexts let you drop privileges, enforce read-only filesystems, and block dangerous capabilities:
securityContext:
runAsNonRoot: true
runAsUser: 1000
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
Most applications don't need to write to their container filesystem. If yours does, mount an emptyDir volume for scratch space instead of allowing writes everywhere. The read-only root filesystem prevents an attacker from installing tools or modifying binaries after compromise.
Capabilities are the granular Linux permissions that make up root. Dropping all of them and selectively adding back only what you need (NET_BIND_SERVICE for low ports, for example) shrinks your attack surface significantly.
Some images bake in root assumptions. You'll find hardcoded /tmp writes or startup scripts that expect UID 0. When that happens, you either need to rebuild the image properly or use init containers to fix permissions before your main container starts.
Implement network policies to restrict pod communication
By default, every pod can talk to every other pod in your cluster. That's convenient for getting started and dangerous for production. A compromised frontend shouldn't be able to directly query your database pods.
Network policies work like firewall rules for pods. You define which traffic is allowed; everything else is denied:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: db-policy
spec:
podSelector:
matchLabels:
app: database
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app: api
ports:
- protocol: TCP
port: 5432
This policy says database pods only accept connections from pods labeled app: api on port 5432. Everything else is blocked by default.
Your CNI plugin must support network policies—Calico, Cilium, and Weave do; the basic kubenet doesn't. Check before you write policies that silently do nothing.
Start with a default-deny policy for each namespace, then explicitly allow required flows. It's more work upfront but far easier to audit than a permissive mesh with scattered allow rules.
Use namespaces and resource quotas to prevent noisy neighbors
Namespaces aren't just organizational folders. They're the boundary for applying resource quotas, network policies, and RBAC rules. Without them, one team's batch job can consume all cluster memory and starve production services.
Resource quotas limit aggregate resource usage per namespace:
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-quota
namespace: development
spec:
hard:
requests.cpu: "10"
requests.memory: "20Gi"
limits.cpu: "20"
limits.memory: "40Gi"
Once a quota is in place, every pod in that namespace must specify resource requests and limits. This forces developers to think about resource consumption instead of deploying unbounded workloads.
LimitRanges provide default and maximum values for individual pods or containers. They catch the case where someone sets a request but forgets a limit, or tries to deploy a single pod that claims the entire quota.
Separate your environments into distinct namespaces at minimum: production, staging, development. Better yet, split by team or application boundary if you're running a multi-tenant cluster. The isolation prevents accidental cross-contamination and makes blast radius smaller when something goes wrong.
How do I choose the right resource requests for my application?
Monitor actual usage for a few days under typical load using metrics-server or Prometheus. Set requests at the 50th percentile of usage and limits at the 95th. Your app should rarely hit the limit in normal operation.
What happens if I don't set resource limits?
Pods without limits can consume all available resources on their node. One memory leak can trigger OOM kills across unrelated workloads. CPU won't kill pods but it will throttle everything into slow motion.
Should I use blue-green or canary deployments?
Canary works better for gradual risk reduction—you send a small percentage of traffic to the new version and increase it as metrics look good. Blue-green is faster but riskier since you cut over all at once. Use canary for user-facing services and blue-green for internal APIs where you can tolerate a quick rollback.
Do I need network policies if my cluster is already behind a firewall?
Yes. External firewalls protect the cluster perimeter but they don't limit east-west traffic between pods. Network policies implement zero-trust inside the cluster, which matters when one compromised pod tries to pivot laterally.
What happens when you skip these patterns
Every production incident I've debugged in Kubernetes traced back to at least one of these seven patterns being absent. Resource limits prevent OOM cascades. Probes catch stuck containers before users do. PDBs keep your maintenance from becoming downtime.
Security contexts and network policies won't prevent every attack, but they make lateral movement and privilege escalation substantially harder. Namespaces and quotas keep one team's mistake from becoming everyone's outage.
These aren't theoretical best practices. They're the minimum configuration required to run workloads that stay up, scale predictably, and fail gracefully when something does go wrong.
