Monitoring Horizontal Pod Autoscaling in Kubernetes

Fix Apache Issue

3 min

1. Kubernetes Resources

Especially in production Kubernetes clusters, CPU and memory are precious resources. Cluster operators normally require you to specify the CPU and memory your Pod needs so the scheduler can place it on a Node with sufficient capacity.

You do this by adding a resources section to the container specification:

yaml
resources:
  limits:         # Maximum amount of CPU & memory for peak use
    cpu: "8"      # Maximum of 8 CPU cores allowed at peak use
    memory: "4Mi" # Maximum allowed 4 MiB of memory
  requests:       # Expected amount of CPU & memory for normal use
    cpu: "6"      # Requesting 6 CPU cores
    memory: "2Mi" # Requesting 2 MiB of memory

More information can be found here: Resource Management for Pods and Containers

If a container exceeds its memory limit, Kubernetes terminates and restarts it (OOMKilled) to protect other workloads on the Node.

If there is not enough unallocated CPU or memory on any Node to satisfy a Pod’s requests, the scheduler leaves the Pod in Pending state until capacity becomes available.

2. Fix the CPU Request

Exercise Lower the CPU request and limit

Before making changes, check Alerts & Detectors in Splunk Observability Cloud to see which detector has fired for the apache namespace (you can also see this in Kubernetes Navigator and Log Observer).

Edit ~/workshop/k3s/apache-hpa.yaml to reduce the CPU resources:

bash
vim ~/workshop/k3s/apache-hpa.yaml

Find the resources section and set the CPU limit to 1 and the CPU request to 0.5:

yaml
resources:
  limits:
    cpu: "1"
    memory: "4Mi"
  requests:
    cpu: "0.5"
    memory: "2Mi"

Save the file (press Esc, then :wq!).

Delete and recreate the StatefulSet so Kubernetes schedules apache-hpa-0 with the new CPU request (a StatefulSet’s RollingUpdate controller will not replace a pod that is stuck in Pending):

bash
kubectl delete -f ~/workshop/k3s/apache-hpa.yaml -n apache
kubectl apply -f ~/workshop/k3s/apache-hpa.yaml -n apache

Validate the changes have been applied:

bash
kubectl describe statefulset apache-hpa -n apache

Watch the pod status in your terminal (kubectl get pods -n apache) and in Splunk Observability Cloud.

Quick check

After fixing the CPU request, why does the apache-hpa-0 pod fail to stay healthy?

3. Fix the Memory Limit

Exercise Increase the memory request and limit

Edit the StatefulSet live to give Apache enough memory to run under load:

bash
kubectl edit statefulset apache-hpa -n apache

Update the resources section to match:

yaml
resources:
  limits:
    cpu: "1"
    memory: 32Mi
  requests:
    cpu: 500m
    memory: 16Mi

Save and exit (Esc, then :wq!). Because apache-hpa-0 is stuck in CrashLoopBackOff, delete the pod so the StatefulSet immediately recreates it with the updated memory limits:

bash
kubectl delete pod apache-hpa-0 -n apache

Verify the pod is Running and healthy:

bash
kubectl get pods -n apache
kubectl describe statefulset apache-hpa -n apache

Confirm in the Apache web servers (OTel) Navigator (filter by k8s.cluster.name = <your_cluster>) that metrics are now flowing steadily.

Last Modified ·

Report an issue