KCNA — Cost Management

3 minute read

Cost Management in Cloud Native

Running workloads in the cloud isn’t free. Understanding cost management practices — often called FinOps — is part of the KCNA exam’s observability domain.


Why Cost Management Matters

Common cost problems in Kubernetes:

Problem Description
Over-provisioning Requesting more CPU/memory than needed — wasting resources
Under-utilization Nodes running at 20% capacity — paying for idle resources
No limits Pods without resource limits consuming more than their share
Idle resources Dev/staging environments running 24/7 unnecessarily
Orphaned resources PersistentVolumes, load balancers still running after workloads are deleted

FinOps — Cloud Financial Management

FinOps (Financial Operations) is the practice of bringing financial accountability to cloud spending.

FinOps Principles

Principle Description
Teams own their costs Engineering teams are responsible for their cloud spend
Centralized best practices A FinOps team provides tools, guidelines, and training
Timely reports Real-time cost data drives better decisions
Business value drives decisions Spending should align with business outcomes
Take advantage of the cloud model Use reserved instances, spot instances, right-sizing

FinOps Lifecycle

Inform → Optimize → Operate
  │          │          │
  ▼          ▼          ▼
Visibility  Action    Governance
(dashboards) (right-size) (policies)
  1. Inform: Gain visibility into who is spending what and why
  2. Optimize: Take action to reduce waste (right-sizing, reserved instances)
  3. Operate: Establish ongoing governance and automation

Resource Optimization in Kubernetes

Resource Requests and Limits

resources:
  requests:
    cpu: "250m"       # Minimum guaranteed CPU
    memory: "256Mi"   # Minimum guaranteed memory
  limits:
    cpu: "500m"       # Maximum CPU allowed
    memory: "512Mi"   # Maximum memory allowed
Concept Purpose Cost Impact
Requests Guaranteed minimum resources — used for scheduling Over-requesting wastes capacity
Limits Maximum allowed resources — prevents runaway usage Too high = waste; too low = throttling

Right-Sizing

Right-sizing means matching resource requests to actual usage:

Before Right-Sizing:
Request: 1 CPU, 2Gi RAM
Actual:  0.2 CPU, 400Mi RAM
Waste:   80% CPU, 80% RAM

After Right-Sizing:
Request: 300m CPU, 512Mi RAM
Actual:  200m CPU, 400Mi RAM
Waste:   Minimal

Tools for right-sizing:

  • VPA (Vertical Pod Autoscaler) — recommends optimal resource requests
  • Prometheus + Grafana — visualize actual vs requested resources
  • Kubecost — cost allocation and optimization recommendations

Cost Optimization Strategies

1. Right-Size Resources

Set requests and limits based on actual usage data.

2. Use Autoscaling

  • HPA: Scale pods to match demand — don’t run excess replicas
  • Cluster Autoscaler: Remove underutilized nodes
  • KEDA: Scale to zero when no events

3. Spot/Preemptible Instances

Use discounted, interruptible cloud instances for fault-tolerant workloads:

Provider Name Typical Discount
AWS Spot Instances Up to 90% off
GCP Preemptible VMs / Spot VMs Up to 91% off
Azure Spot VMs Up to 90% off

Best for: batch processing, CI/CD, stateless workloads.

4. Reserved Instances / Committed Use

Pre-commit to usage for 1-3 years at significant discounts:

  • Use for stable, predictable workloads
  • Combine with spot instances for variable workloads

5. Namespace Cost Allocation

Use Kubernetes namespaces to track costs per team or project:

namespace: team-payments  → Cost: $X/month
namespace: team-orders    → Cost: $Y/month
namespace: dev-staging    → Cost: $Z/month

6. Schedule Non-Production Environments

Scale down dev/staging environments during off-hours:

  • Use CronJobs or automation to scale to 0 replicas at night
  • Scale back up during business hours
  • Can save 65%+ on non-production costs

LimitRange and ResourceQuota

Kubernetes provides built-in tools for cost governance:

LimitRange

Sets default and maximum resource limits per namespace:

apiVersion: v1
kind: LimitRange
metadata:
  name: default-limits
  namespace: team-payments
spec:
  limits:
  - default:
      cpu: "500m"
      memory: "512Mi"
    defaultRequest:
      cpu: "250m"
      memory: "256Mi"
    type: Container

ResourceQuota

Limits total resource consumption per namespace:

apiVersion: v1
kind: ResourceQuota
metadata:
  name: team-quota
  namespace: team-payments
spec:
  hard:
    requests.cpu: "10"
    requests.memory: "20Gi"
    limits.cpu: "20"
    limits.memory: "40Gi"
    pods: "50"

Cost Observability Tools

Tool Type Description
Kubecost Open-source Cost allocation and optimization for K8s
OpenCost CNCF Sandbox Open standard for K8s cost monitoring
AWS Cost Explorer Cloud provider AWS-specific cost analysis
GCP Billing Cloud provider GCP-specific cost analysis
Azure Cost Management Cloud provider Azure-specific cost analysis

OpenCost is a CNCF Sandbox project that provides a vendor-neutral standard for Kubernetes cost monitoring.


KCNA Exam Tips

  • Know the FinOps lifecycle: Inform → Optimize → Operate
  • Resource requests are for scheduling; limits are for enforcement
  • Right-sizing means matching requests to actual usage
  • Spot/preemptible instances provide significant discounts for fault-tolerant workloads
  • LimitRange sets defaults per container; ResourceQuota limits total per namespace
  • OpenCost is the CNCF Sandbox project for cost monitoring
  • Autoscaling (HPA, Cluster Autoscaler, KEDA) helps optimize costs dynamically

What’s Next?

Test your knowledge of observability with practice questions.

Next: Practice Questions →

Updated: