Kubernetes Architecture Deep Dive: From Resource Limits to Custom Operators

2026年8月12日1 次浏览来源:Dev.to阅读原文

Resource Management (Requests & Limits) Resource management prevents Kubernetes workloads from depleting node hardware or causing resource contention among containers.

Resource Requests The absolute minimum CPU and Memory guaranteed for a Pod to start.

The Kubernetes Scheduler uses requests to determine node placement.

If a node cannot fulfill the requested resources, the Pod will not be scheduled on that node.

Architectural Takeaway: Omitting requests leads to poor scheduling decisions, resulting in unbalanced cluster distribution and potential node starvation.

Resource Limits The maximum ceiling of CPU and Memory a Pod is allowed to consume.

Memory (Non-Compressible Resource): If a process (e.g., a memory-heavy Pandas pipeline) exceeds its memory limit by even 1 MB, the Linux Kernel terminates the container with an OOMKilled (Out Of Memory Killed) exit code.

This acts as a critical safety circuit breaker to constrain the blast radius and protect co-located services.

CPU (Compressible Resource): Unlike memory, exceeding CPU limits does not terminate the pod.

Instead, the Linux Completely Fair Scheduler (CFS) enforces CPU Throttling.

This constrains CPU usage, keeping the application alive but causing severe latency spikes during heavy traffic.

Architectural Takeaway: Memory limits protect nodes from crashing due to leaks, while improperly tuned CPU limits risk performance degradation via throttling even when the host node has idle CPU capacity.

Advanced Architectural Concepts Beyond basic resource allocation, managing production Kubernetes clusters requires an understanding of hardware overcommitment, Linux Kernel throttling mechanics, and implicit Quality of Service (QoS) eviction hierarchies.

Resource Overcommit Overcommit occurs when the sum of all container resource limits on a node exceeds the node's actual physical hardware capacity, while the sum of resource requests remains within capacity bounds.

The Economics: In cloud infrastructure, running compute nodes at 20% average utilization is an expensive waste.

Overcommit allows engineering teams to pack more workloads onto fewer nodes by betting that not all pods will hit their maximum resource limits simultaneously.

The Overcommit Trade-off: CPU Overcommit: Safe and manageable.

CPU is a compressible resource; if demand exceeds capacity, execution speed slows down across pods.

Memory Overcommit: High risk.

Memory is non-compressible.

If multiple pods suddenly spike toward their memory limits concurrently, the node runs out of physical RAM and swap.

The Linux Kernel triggers events to forcibly terminate containers and reclaim memory.

Architectural Takeaway: Calculate the Overcommit Ratio carefully.

Overcommit CPU aggressively to save money, but keep memory overcommit conservative to avoid cascading application crashes.

The Linux CFS Quota & CPU Throttling Trap Setting CPU limits relies on the Linux Kernel Completely Fair Scheduler (CFS) using enforcement.

The Kernel evaluates CPU usage in enforced time windows, typically every 100ms (the CFS Period).

How the Trap Works: If a pod with a CPU limit of (1000m) executes a multi-threaded operation that consumes 100ms worth of CPU processing time within the first 20ms of a period, the Kernel locks out the pod's CPU access for the remaining 80ms of that window.

The Idle Node Paradox: A pod can experience severe CPU Throttling (causing 500ms+ latency spikes in HTTP services) even when the underlying host worker node shows 80% idle CPU capacity.

Architectural Takeaway: Many enterprise SRE teams disable CPU limits entirely () for latency-sensitive microservices, relying strictly on well-tuned CPU Requests paired with Horizontal Pod Autoscaler (HPA) to handle traffic spikes safely.

Quality of Service (QoS) Classes & Eviction Order Kubernetes automatically assigns every pod a QoS Class based on how its container requests and limits are configured.

When a worker node experiences memory pressure, the Linux Kernel and Kubernetes Kubelet use the QoS class to determine eviction priority via the metric.

Guaranteed (Highest Priority / Protected) Condition: Every container in the pod must explicitly specify both CPU and Memory, and for all resources.

Behavior: Highly stable.

Granted an of .

These pods are the absolute last to be evicted or terminated during node memory starvation.

Ideal for databases, core stateful sets, and critical payment services.

Burstable (Medium Priority / Standard) Condition: At least one container specifies a request or limit, but (or CPU has a limit while Memory does not).

Behavior: Allowed to burst beyond baseline when capacity allows.

Evicted after all pods are killed if memory pressure persists.

Ideal for web APIs, background workers, and standard web applications.

BestEffort (Lowest Priority / Disposable) Condition: No requests or limits are defined for any container in the pod.

Behavior: Assigned an of .

Gets access to unallocated node resources, but is the first target for termination during node memory pressure.

Ideal for non-critical batch processing, dev/test pods, or temporary log collectors.

Security and Observability The control mechanisms that keep the system resilient before everything crashes or when a breach occurs.

RBAC (Role-Based Access Control) The identity card and permission firewall for your code.

It strictly limits what a Pod (or a user) can execute within the system.

ServiceAccount: The identity assigned to a Pod.

Role/ClusterRole: The explicit list of allowed permissions.

RoleBinding/ClusterRoleBinding: The bridge that staples an identity to a set of permissions.

Even if a vulnerability leaks into the application code, RBAC prevents lateral movement and protects the underlying infrastructure.

Monitoring & Alerting Kubernetes knows whether an application is running, but it is blind to the question: “Is the business logic actually behaving correctly?” To solve this: Prometheus: Continuously scrapes and collects every metric (CPU, API response times, queue lengths, etc.) from the system.

Grafana: Transforms raw time-series metrics into visual, customizable dashboards.

Alertmanager: Triggers notifications (Slack, PagerDuty, Email) when response latency spikes from 200ms to 4 seconds, or when errors start popping up.

Service Mesh (Istio/Linkerd) An infrastructure highway that manages, encrypts, and observes inter-service communication (East-West Traffic).

Sidecar Proxy: A lightweight proxy (like Envoy or NGINX) injected alongside your main application container inside the same Pod.

It intercepts all inbound and outbound traffic completely transparently to your application code. mTLS (Mutual TLS): Automatically encrypts network traffic between microservices in transit.

Even if an attacker intercepts the network traffic, the payload remains unreadable.

Traffic Splitting: Allows you to route a portion of live traffic (e.g., 10%) to a new application version (Canary deployment) without altering a single line of application code.

Pod Lifecycle and Probes Kubernetes evaluates the true health and readiness of an application inside a Pod using three distinct types of Probes.

Startup Probe Ensures Kubernetes remains patient while an application boots up (for instance, legacy Java applications that might take over a minute to initialize).

No other probes run until the Startup Probe succeeds.

If this probe fails, Kubernetes assumes the application is stuck during startup and immediately restarts the Pod.

Liveness Probe Answers the question: “Is this Pod alive?” If the application enters a deadlock or infinite loop, Kubernetes detects the stall via the probe, terminates the unresponsive container, and restarts it according to the restart policy.

Readiness Probe Answers the question: “This Pod is alive, but is it ready to accept incoming user requests?” For example, the application process might be running, but it’s still establishing connection to a database.

If this probe fails, Kubernetes does NOT kill or restart the Pod; it s

分享
Baike.dev

baike.dev helps you discover great languages, frameworks, databases, DevOps and cloud-native tools.

Quick links

About

Contribute

Found a great developer tool? Share it with the community.

Submit a tool
© 2026 baike.dev Developer EncyclopediaUpdated daily · Discover great developer tools