AWS Logo
Menu
Optimizing costs on your Amazon EKS

Optimizing costs on your Amazon EKS

Amazon EKS (Elastic Kubernetes Service) cluster is crucial, as costs can quickly add up if resources are not managed efficiently

Published Feb 19, 2025
  • "Recently, I discovered that our production environment contains the following resources, which are inactive and not in use but still generating costs. Since this is a production environment, it may be difficult to notice these unused resources:-
  • Unattached EBS volumes
  • Old Load Balancers (ELBs)
  • Idle EBS snapshots
  • Unused Persistent Volumes (PVs) and Persistent Volume Claims (PVCs)
  • Orphaned IPs (Elastic IPs still allocated but not in use)"
so i will dive deep one by one on how to identify this resources and to check if they are in use or not before getting rid of it incase if they are not in use.

Check & Delete Unattached EBS Volumes

Using AWS Console:
  • Go to EC2 DashboardVolumes.
  • Look for volumes with State = Available (this means they are not attached to any EC2 instance).
  • Check Tags to verify they are not needed (some might be used for future reattachment).
This is an example of volume not in use so you can check properly , so in my own case i clicked on the volume with available and since i don't need it for future re attachement i delete it
You can also use command line to check
aws ec2 describe-volumes --filters Name=status,Values=available --query "Volumes[*].{ID:VolumeId,Size:Size,AZ:AvailabilityZone,Created:CreateTime}" --output table
How to Delete Unattached EBS Volumes
aws ec2 delete-volume --volume-id <VOLUME_ID>
Replace <VOLUME_ID> with the actual volume ID.

Check & Delete Old Load Balancers (ELBs)

Load Balancers (Classic, ALB, NLB) left unused continue to incur hourly charges.

How to Check Unused Load Balancers

  1. Using AWS Console:
    • Go to EC2 DashboardLoad Balancers.
    • Look for ELBs with zero active instances (no instances registered).
    • Check last activity (if it's old, it might be unused).
  2. Using AWS CLI:shCopiaModificaaws elbv2 describe-load-balancers --query "LoadBalancers[*].{Name:LoadBalancerName,State:State.Code,ARN:LoadBalancerArn}" --output table
    • If the State is "active" but unused, consider deleting.

How to Delete Old Load Balancers

  • For Classic Load Balancer:
  • aws elb delete-load-balancer --load-balancer-name <ELB_NAME>
  • For ALB/NLB:-
  • aws elbv2 delete-load-balancer --load-balancer-arn <ELB_ARN>

Check & Delete Idle EBS Snapshots

EBS snapshots stored in S3 can accumulate storage costs if not needed.

How to Check Idle EBS Snapshots

  1. Using AWS Console:
    • Go to EC2 DashboardSnapshots.
    • Identify old snapshots that are not linked to active EBS volumes.
  2. Using AWS CLI: aws ec2 describe-snapshots --owner-id self --query "Snapshots[*].{ID:SnapshotId,StartTime:StartTime,Size:VolumeSize}" --output table

How to Delete Unused Snapshots

aws ec2 delete-snapshot --snapshot-id <SNAPSHOT_ID>
If you need to retain the snapshot but want to reduce costs, move it to Amazon S3 Glacier for cheaper long-term storage.

Check & Delete Unused Persistent Volumes (PVs) and Persistent Volume Claims (PVCs)

EKS automatically provisions Persistent Volumes (PVs) and Persistent Volume Claims (PVCs), but unused ones still take up EBS storage.

How to Check Unused PVs and PVCs

  1. List all PVs in your EKS cluster: kubectl get pv
    Look for PVs with "Released" or "Available" status (these are not in use).
  2. List all PVC kubectl get pvc --all-namespaces
    If a PVC is not attached to a running pod, it may be unused.

How to Delete Unused PVs and PVCs

  • Delete PVC (this will also delete the linked PV if using dynamic provisioning):
  • kubectl delete pvc <PVC_NAME> -n <NAMESPACE>
  • Manually delete PV if still lingering:
  • kubectl delete pv <PV_NAME>

Check & Release Orphaned Elastic IPs (EIPs)

Elastic IPs (EIPs) incur charges if they are allocated but not attached to an active EC2 instance.

How to Check Unused Elastic IPs

  1. Using AWS Console:
    • Go to EC2 DashboardElastic IPs.
    • Look for Elastic IPs that are not associated with any instance.
  2. Using AWS CLI: aws ec2 describe-addresses --query "Addresses[?AssociationId==null].{PublicIP:PublicIp,AllocationId:AllocationId}" --output table

How to Release Orphaned Elastic IPs

aws ec2 release-address --allocation-id <ALLOCATION_ID>
If an IP is needed for future use, consider stopping charges by attaching it to a low-cost EC2 instance instead of keeping it idle.

Regular Cost Optimization Checks

Use AWS Trusted Advisor – Detects unused resources automatically.
Enable AWS Budgets & Cost Anomaly Detection – Alerts for unexpected cost spikes.
Use Kubecost – Monitors EKS costs per namespace/workload.
 

Comments