Cloud Infrastructure··3 min read

How We Cut AWS EC2 Compute Bills by 35% with K3s Pod Request Tuning and Kyverno Admission Policies

Shafikul Islam

Shafikul Islam

Backend & Cloud Infrastructure Engineer · Infrastructure & Cloud Team Lead

How We Cut AWS EC2 Compute Bills by 35% with K3s Pod Request Tuning and Kyverno Admission Policies

The Hidden Tax of Copy-Pasted Kubernetes Resource Requests

When a Kubernetes cluster keeps spinning up new AWS EC2 worker nodes while actual CPU utilization sits below 22%, the problem is almost never traffic growth.

The Kubernetes scheduler (kube-scheduler) does not schedule pods based on real-time CPU or memory usage. It schedules pods strictly against resources.requests. If 30 microservices copy-paste requests.cpu: 1000m from a starter Helm template while only consuming 75m at peak traffic, the scheduler marks the worker nodes as full and triggers cluster autoscaling for ghost capacity.

Here is how we cut our monthly AWS EC2 compute bill by 35% across our production K3s clusters at Cansoft Technologies with zero downtime.


1. Auditing 14-Day P99 Usage Against Provisioned Requests in Prometheus

Before changing a single Helm chart, we ran a 14-day Prometheus query comparing the 99th percentile actual CPU usage of every deployment against its configured CPU request:

quantile_over_time(
  0.99,
  rate(container_cpu_usage_seconds_total{container!="", image!=""}[5m])[14d:5m]
)
/
on (namespace, pod, container)
kube_pod_container_resource_requests{resource="cpu"}

Over 65% of our internal stateless services were using less than 12% of their requested CPU and less than 28% of their requested memory.


2. Right-Sizing Requests and Tuning Horizontal Pod Autoscalers (HPA)

We applied a deterministic sizing formula across every microservice:

  • CPU Request: Set to 1.25x of 14-day P95 usage so normal traffic never throttles.
  • CPU Limit: Removed hard CPU limits on latency-sensitive API pods to avoid Linux CFS bandwidth throttling spikes when spare node cores are idle.
  • Memory Request & Limit: Set equal (Guaranteed QoS for stateful workers, or 1.3x P99 working set for API pods) to eliminate unexpected OOMKills.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: billing-webhook-worker
spec:
  template:
    spec:
      containers:
        - name: worker
          resources:
            requests:
              cpu: "120m"
              memory: "192Mi"
            limits:
              memory: "256Mi"
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: billing-webhook-worker-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: billing-webhook-worker
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70

3. Preventing Regression with Kyverno Policies and CI Hygiene Checks

Right-sizing once is useless if developers merge new bloated YAML manifests the following week. We added a Kyverno ClusterPolicy and a Go CLI check in GitHub Actions that blocks any pull request missing explicit resource bounds or requesting more than 500m CPU without an architecture exemption label.

Within 48 hours of rolling out the right-sized Helm charts via ArgoCD, we drained and terminated 35% of our EC2 worker nodes with zero latency degradation.

Infrastructure & PostgreSQL Advisory

Scaling Infrastructure or Diagnosing P95 Latency?

I help engineering teams diagnose PostgreSQL indexing bottlenecks, concurrency limits, and K3s/Docker deployments. Book a 20-minute call with me to review your setup.

Related Technical Articles