Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Operations
24 min read

7 Kubernetes Production Pitfalls the Docs Don't Cover

This article details seven real-world Kubernetes production incidents—including etcd disk exhaustion, CoreDNS ndots latency, Secret update propagation, HPA scheduling failures, node drain disruptions, log collector resource starvation, and rolling update connection drops—with root causes, emergency fixes, and permanent preventive configurations.

Running Kubernetes in production reveals gaps the official documentation never mentions. Below are seven hard-learned lessons from actual outages, each with the failure scenario, root-cause analysis, emergency mitigation, and long-term prevention.

Pitfall 1: etcd Disk Full → Cluster Goes Read-Only

Symptom: kubectl run returns etcdserver: request timed out; journalctl -u etcd shows mvcc: database space exceeded.

Root cause: etcd has a default 2 GB quota. A misbehaving service in CrashLoopBackOff generated over 1 million Event objects in three days, filling the quota. Once exceeded, etcd rejects all writes, freezing the entire cluster.

Emergency fix: temporarily raise the quota to 8 GB:

etcdctl --endpoints=https://127.0.0.1:2379 \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  put quota/bytes -- '8589934592'

Cleanup: delete old events (keep last hour):

kubectl get events --all-namespaces --field-selector eventTimestamp<2026-04-27T09:00:00Z \
  | awk '{print $1}' | sort -u | xargs -I {} kubectl delete events --field-selector eventTimestamp<2026-04-27T09:00:00Z -n {}

Permanent prevention: set event TTL in kube-controller-manager:

# /etc/kubernetes/manifests/kube-controller-manager.yaml
spec:
  containers:
  - command:
    - kube-controller-manager
    - --terminated-pod-gc-threshold=1000
    - --event-ttl=1h
Lesson: etcd storage is the cluster lifeline. Monitor usage; alert at 70%.

Pitfall 2: CoreDNS ndots:5 Makes DNS Resolution 5× Slower

Symptom: first request to a short name (e.g., mysql) takes 2–3 seconds; subsequent requests are fast.

Root cause: Pod /etc/resolv.conf contains options ndots:5. With

search default.svc.cluster.local svc.cluster.local cluster.local

, a name with fewer than 5 dots gets each search suffix appended sequentially. Each NXDOMAIN waits for timeout (default 5 s), so dev-service tries four suffixes before falling back to the raw name.

Solutions:

Option 1 (simplest): use fully qualified names ( mysql.default.svc.cluster.local).

Option 2 (recommended): lower ndots to 2 in CoreDNS ConfigMap and Pod dnsConfig:

# CoreDNS ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
data:
  Corefile: |
    .:53 {
      errors
      health
      kubernetes cluster.local in-addr.arpa ip6.arpa {
        pods insecure
        fallthrough in-addr.arpa ip6.arpa
        ttl 30
      }
      prometheus :9153
      forward . /etc/resolv.conf {
        max_concurrent 1000
      }
      cache 30
      loop
      reload
      loadbalance
    }
# Pod dnsConfig
spec:
  dnsConfig:
    options:
    - name: ndots
      value: "2"

Option 3: create a headless Service for the short name so it resolves directly.

Lesson: If your apps use short names, reduce ndots to 2; it covers most cases and drastically cuts DNS queries.

Pitfall 3: Secret Updated but Pod Still Sees Old Value

Scenario: an API key stored in a Secret is rotated via

kubectl create secret ... --dry-run=client -o yaml | kubectl apply -f -

. Half an hour later the third-party API still receives the old key.

Root cause: two mount mechanisms behave differently:

Environment variables: injected at Pod start; never update. Pod must restart.

Volume mount: kubelet syncs the file periodically (~1 minute). No restart needed.

The team used environment variables, so the running Pod kept the stale value.

Fixes:

Short term: kubectl rollout restart deployment app-service.

Long term: switch to volume mount and add application-level file watching (example in Go using fsnotify).

Lesson: Document clearly: if Secret is mounted as env vars, a Pod restart is mandatory after update.

Pitfall 4: HPA Scales Up but New Pods Stay Pending

During traffic peak HPA increased replicas from 3 to 8, yet 5 new Pods remained Pending with Insufficient cpu / memory.

Root cause: Pod requests were set far below actual usage (100m CPU request vs. 800–1500m actual). The scheduler packed many Pods onto nodes based on requests; when load spiked, nodes had no headroom for new Pods.

Emergency: evict low-priority Pods, scale down non-critical deployments.

Long term: set requests to 70–80% of observed actual usage (P50/P70 from kubectl top pod). Example:

resources:
  requests:
    cpu: "800m"
    memory: "512Mi"
  limits:
    cpu: "2000m"
    memory: "2Gi"
Lesson: Low requests aren't “saving resources”—they deceive the scheduler. Set requests near real consumption.

Pitfall 5: kubectl drain Takes Down Multiple Services

Draining three worker nodes sequentially for kernel upgrades caused widespread 5xx errors.

Root cause: Pods lacked graceful termination. Default terminationGracePeriodSeconds=30 but apps ignored SIGTERM, so kubelet sent SIGKILL after 30 s. During those 30 s the Pod remained in Service endpoints, receiving new requests it couldn't handle. Simultaneous drains amplified the effect.

Fixes:

Add graceful shutdown: terminationGracePeriodSeconds: 60 + preStop hook ( sleep 10) to allow endpoint removal before SIGTERM.

Create PodDisruptionBudget (e.g., minAvailable: 50%) so drain refuses to evict if it would breach availability.

Drain nodes one at a time, waiting for full Pod migration before proceeding.

Lesson: drain triggers a chain reaction. Prerequisites: PDB, graceful termination, single-node operations.

Pitfall 6: Log Collector (Fluentd) Consumes 90%+ CPU, Node Crashes

At 3 AM several workers hit 100% CPU; top showed Fluentd DaemonSet processes at 95% CPU.

Root cause: a developer temporarily set a service to DEBUG log level, generating hundreds of MB/s. Fluentd, running as a DaemonSet on every node, tried to parse and forward all of it, starving the node.

Emergency: add resource limits to Fluentd DaemonSet ( limits.cpu: 1000m), then revert the log level.

Long term:

Enforce requests and limits on every DaemonSet (logging, monitoring agents).

Configure Fluentd rate limiting ( throttle filter, e.g., 100 records/sec per log stream).

Alert on DaemonSet CPU/memory usage.

Lesson: DaemonSet components run everywhere; without limits a single misbehaving log source can kill the whole cluster.

Pitfall 7: Rolling Update Causes 1–2% 502 Errors

Standard kubectl set image rolling update produced brief 502 spikes.

Root cause: readiness probe was a TCP port check. The port opened early (JVM start → Spring init → DB pool → cache load → listen), but the app wasn't ready to serve traffic. Old Pods were removed from endpoints immediately upon deletion, without graceful connection drain.

Fixes:

Replace TCP probe with HTTP /health/ready that verifies DB pool and cache readiness.

Add preStop hook ( sleep 10) so endpoint controller removes the Pod before SIGTERM.

Set deployment strategy: maxSurge: 1, maxUnavailable: 0 to maintain full capacity during rollout.

Lesson: Zero-downtime rollouts require three pieces: HTTP readiness probe, preStop + adequate grace period, and proper maxSurge / maxUnavailable .

Pre-Production Checklist

1. etcd monitoring + event TTL – prevent cluster freeze; set --event-ttl=1h, alert at 70% storage.

2. DNS ndots configuration – avoid first-request latency; set ndots=2, use FQDNs.

3. Secret mount method – ensure updates propagate; use volume mounts for hot reload, else restart Pods.

4. Realistic resource requests – enable HPA scaling; set requests to 70–80% of actual usage.

5. PodDisruptionBudget + graceful termination – safe node maintenance; configure PDB, preStop, terminationGracePeriodSeconds.

6. DaemonSet resource limits – protect nodes from log/monitoring storms; enforce limits on all DaemonSets.

7. Zero-downtime rollout config – eliminate 502s; HTTP readiness, preStop, maxSurge/maxUnavailable.

Source:

https://zhuanlan.zhihu.com/p/2032103504307822738

For attribution, corrections or content rights, contactadmin@besthub.dev

Report an issue with this article

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion