Learning Kubernetes From Scratch (Part 7) – Resource Management & Health Checks
By Newt / March 7, 2026 / No Comments / Kubernetes
βοΈ 1. Resource Management Testing
One of the most powerful features in Kubernetes is the ability to control how much CPU and memory a container is allowed to use. Without limits, a single container could consume all the node resources and impact other applications running in the cluster.
| Setting | Purpose |
|---|---|
| Request | Minimum resources Kubernetes guarantees for the container |
| Limit | Maximum resources the container is allowed to consume |
π Resource Test Deployment File
File: 08-resource-test.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: resource-test
spec:
replicas: 1
selector:
matchLabels:
app: resource-test
template:
metadata:
labels:
app: resource-test
spec:
containers:
- name: stress-container
# This container intentionally generates CPU load
# It allows us to observe how Kubernetes enforces limits
image: polinux/stress
# Run stress tool to consume CPU
args: ["--cpu", "1"]
resources:
# Guaranteed CPU allocation
requests:
cpu: "250m"
# Maximum CPU allowed
limits:
cpu: "500m"
This deployment launches a container that intentionally generates CPU load using the stress utility. Because we defined both requests and limits, Kubernetes can enforce resource rules.
- π§ 250m request means the container is guaranteed 0.25 CPU.
- π¦ 500m limit means it cannot exceed half a CPU core.
- β‘ If it tries to use more than that, Kubernetes will throttle the container.
π Apply the Deployment
kubectl apply -f 08-resource-test.yaml
This command creates the deployment and schedules the pod on a node. The container will immediately begin generating CPU load.
π Watch the Pod in Real Time
kubectl get pods -l app=resource-test -w
This command streams pod status updates in real time.
- -l filters pods using a label selector
- -w enables live watch mode
π Inspect Pod Resource Settings
kubectl describe pod -l app=resource-test
This command displays detailed pod information including:
- Configured CPU requests and limits
- Events related to resource throttling
- Container lifecycle events
π Check Real-Time Resource Usage
kubectl top pod -l app=resource-test
This shows the actual CPU and memory usage of the running pod.
β€οΈβπ©Ή 2. Health Check Testing
Kubernetes continuously monitors application health using probes. These checks help Kubernetes automatically detect and recover from application failures.
| Probe | Purpose |
|---|---|
| Readiness Probe | Determines if the pod is ready to receive traffic |
| Liveness Probe | Restarts containers if they become unhealthy |
π Health Check Deployment File
File: 06-health-checks.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-health
spec:
replicas: 1
selector:
matchLabels:
app: nginx-health
template:
metadata:
labels:
app: nginx-health
spec:
containers:
- name: nginx
image: nginx:1.14
ports:
- containerPort: 80
# Readiness probe checks if pod can receive traffic
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5
# Liveness probe ensures container is still healthy
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 15
periodSeconds: 10
This deployment uses two important health mechanisms:
- π’ Readiness probe prevents traffic from reaching a container until it is ready.
- π Liveness probe automatically restarts the container if it becomes unhealthy.
π Deploy the Health Check Example
kubectl apply -f 06-health-checks.yaml
π Watch Pod Status
kubectl get pods -l app=nginx-health -w
Watching pods live allows you to see when:
- Probes succeed
- Probes fail
- Containers restart automatically
π Inspect Probe Configuration
kubectl describe pod -l app=nginx-health
This command shows detailed probe configuration including:
- Probe timing settings
- Failure thresholds
- Probe success/failure events
π Check Container Logs
kubectl logs -l app=nginx-health
Because probes send HTTP requests to nginx, these requests appear inside the nginx access logs. This makes debugging health check issues much easier.
π§Ή 3. Cleanup Commands
After testing is complete, itβs good practice to remove temporary resources from your cluster.
kubectl delete -f 08-resource-test.yaml kubectl delete -f 06-health-checks.yaml
These commands remove both deployments and automatically terminate their associated pods.
β Verify Cleanup
kubectl get all
This command lists all resources in the current namespace. After cleanup, you should only see the default kubernetes service.
