Finops
FinOps - Cloud Financial Management
Section titled “FinOps - Cloud Financial Management”Overview
Section titled “Overview”FinOps (Financial Operations) is the practice of bringing financial accountability to the variable spend model of cloud. It enables organizations to make informed decisions about cloud usage and costs.
FinOps Principles
Section titled “FinOps Principles”┌─────────────────────────────────────────────────────────────────┐│ FinOps Principles ││ ││ ┌──────────────────┐ ││ │ 1. Inform │ ──▶ Visibility into costs ││ └──────────────────┘ ││ │ ││ ▼ ││ ┌──────────────────┐ ││ │ 2. Optimize │ ──▶ Right-size resources ││ └──────────────────┘ ││ │ ││ ▼ ││ ┌──────────────────┐ ││ │ 3. Operate │ ──▶ Continuous improvement ││ └──────────────────┘ │└─────────────────────────────────────────────────────────────────┘FinOps Lifecycle
Section titled “FinOps Lifecycle”┌─────────────────────────────────────────────────────────────────┐│ FinOps Lifecycle ││ ││ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ││ │ Inform │──▶│ Optimize │──▶│ Operate │──▶│ Inform │ ││ └─────────┘ └─────────┘ └─────────┘ └─────────┘ ││ │ │ │ ││ ▼ ▼ ▼ ││ ┌─────────┐ ┌─────────┐ ┌─────────┐ ││ │Cost │ │Rightsizing│ │Budgets │ ││ │Reporting │ │Reserved │ │Alerts │ ││ │ │ │Instances │ │ │ ││ └─────────┘ └─────────┘ └─────────┘ ││ ││ ┌─────────┐ ┌─────────┐ ┌─────────┐ ││ │ Tagging │ │ Spot │ │ Showback│ ││ │ Policies│ │ Usage │ │ /Chargeback ││ └─────────┘ └─────────┘ └─────────┘ │└─────────────────────────────────────────────────────────────────┘Cost Visibility
Section titled “Cost Visibility”Tagging Strategy
Section titled “Tagging Strategy”# Required tags policyrequired_tags: - Environment: [dev, staging, prod] - Team: [platform, payments, analytics] - CostCenter: [CC-001, CC-002, CC-003] - Project: [project-name] - Owner: [email]
# Terraform tagginglocals { common_tags = { Environment = var.environment Team = var.team CostCenter = var.cost_center Project = var.project Owner = var.owner }}
resource "aws_instance" "example" { ami = var.ami_id instance_type = var.instance_type
tags = merge(local.common_tags, var.extra_tags)}Cost Allocation
Section titled “Cost Allocation”# AWS CUR (Cost and Usage Report)resource "aws_cur_report_definition" "example" { report_name = "monthly-cost" time_unit = "HOURLY" format = "Parquet" compression_parquet = "SNAPPY" additional_schema_elements = ["RESOURCES", "SPLIT_COST_ALLOCATION_DATA"]
s3_bucket = aws_s3_bucket.cur.id s3_prefix = "cur/" s3_region = "us-east-1"}Cost Optimization
Section titled “Cost Optimization”Right-Sizing
Section titled “Right-Sizing”# Lambda function for right-sizing recommendationsimport boto3
ce = boto3.client('ce')
def get_rightsize_recommendations(): response = ce.get_rightsizing_recommendations( Filter={ 'CostCategories': { 'Key': 'Environment', 'Values': ['production'] } }, Service='AmazonEC2', LookbackPeriodInDays='30', RecommendationTargetType='SAME_INSTANCE_FAMILY' )
return response['RightsizingRecommendations']
def generate_report(): recommendations = get_rightsize_recommendations()
for rec in recommendations: current = rec['CurrentInstance'] target = rec['RecommendedInstances'][0]
print(f"Save {rec['EstimatedMonthlySavings']} by changing") print(f" {current['InstanceType']} -> {target['InstanceType']}")Reserved Instance Planning
Section titled “Reserved Instance Planning”# Analyze RI coveragedef analyze_ri_coverage(): response = ce.get_reservation_coverage( TimePeriod={ 'Start': '2024-01-01', 'End': '2024-01-31' }, Granularity='MONTHLY' )
for item in response['CoveragesByTime']: coverage = float(item['Coverage']['CoveragePercentage']) print(f"RI Coverage: {coverage:.1f}%")
if coverage < 70: print(" Consider purchasing more Reserved Instances")Spot Instance Strategy
Section titled “Spot Instance Strategy”# Kubernetes Spot instance configurationapiVersion: eksctl.io/v1alpha5kind: ClusterConfigmetadata: name: my-cluster region: us-west-2
managedNodeGroups: - name: on-demand instanceTypes: [m5.large, m5.xlarge] desiredCapacity: 3
- name: spot instanceTypes: [m5n.large, m5.xlarge, m5a.xlarge] desiredCapacity: 10 capacityType: SPOT spotAllocationStrategy: capacity-optimizedBudgets and Alerts
Section titled “Budgets and Alerts”AWS Budgets
Section titled “AWS Budgets”resource "aws_budgets_budget" "example" { name = "monthly-budget" budget_type = "COST" limit_amount = "10000" limit_unit = "USD" time_period_start = "2024-01-01" time_unit = "MONTHLY"
notification { comparison_operator = "GREATER_THAN" threshold = 80 notification_type = "FORECASTED" subscriber_email_addresses = ["team@example.com"] }
notification { comparison_operator = "GREATER_THAN" threshold = 100 notification_type = "ACTUAL" subscriber_email_addresses = ["finance@example.com"] }}Kubernetes Cost Monitoring
Section titled “Kubernetes Cost Monitoring”# Kubecost deploymentapiVersion: helm.cattle.io/v1kind: HelmChartmetadata: name: kubecost namespace: kubecostspec: chart: kubecost repo: https://kubecost.github.io/cost-analyzer targetNamespace: kubecost valuesContent: | kubecostToken: <token> prometheus: nodeExporter: enabled: false grafana: enabled: trueShowback and Chargeback
Section titled “Showback and Chargeback”Cost Report Template
Section titled “Cost Report Template”-- Query for team cost attributionSELECT line_item_usage_account_id as account, product_product_name as service, line_item_usage_type as usage_type, SUM(line_item_unblended_cost) as cost, resource_tags_user_team as team, resource_tags_user_environment as environmentFROM aws_curWHERE line_item_usage_start_date >= DATE_TRUNC('month', CURRENT_DATE)GROUP BY 1, 2, 3, 4, 5ORDER BY cost DESC;Monthly Cost Report
Section titled “Monthly Cost Report”# Cost allocation reportreport: title: "Monthly Infrastructure Cost Report" period: "January 2024"
summary: total_cost: 45000 month_over_month_change: -5%
by_service: - name: EC2 cost: 18000 change: -10% - name: RDS cost: 8000 change: 0% - name: S3 cost: 3000 change: -2% - name: Lambda cost: 2000 change: 5%
by_team: - name: Platform cost: 15000 percentage: 33% - name: Payments cost: 12000 percentage: 27% - name: Analytics cost: 10000 percentage: 22% - name: Other cost: 8000 percentage: 18%
recommendations: - action: "Rightsize 5 EC2 instances" savings: 500 - action: "Purchase RI for stable workloads" savings: 2000 - action: "Delete unused EBS volumes" savings: 300Tools and Platforms
Section titled “Tools and Platforms”Cloud-Native Tools
Section titled “Cloud-Native Tools”| Cloud | Tool | Purpose |
|---|---|---|
| AWS | Cost Explorer | Cost analysis |
| AWS | Budgets | Alerts and budgets |
| AWS | Cost Categories | Cost allocation |
| Azure | Cost Management | Cost analysis |
| Azure | Reservations | Reserved capacity |
| GCP | Billing | Cost analysis |
| GCP | Committed Use | Committed use |
Third-Party Tools
Section titled “Third-Party Tools”| Tool | Purpose |
|---|---|
| Kubecost | Kubernetes cost monitoring |
| CloudHealth | Multi-cloud management |
| Spot.io | Spot instance optimization |
| CloudCheckr | Cost automation |
| Virtuoso | FinOps platform |
Best Practices
Section titled “Best Practices”1. Tag Everything
Section titled “1. Tag Everything”# Terraform enforcementresource "aws_s3_bucket" "example" { bucket = "my-bucket"
tags = { Environment = "prod" Team = "platform" CostCenter = "CC-001" }}2. Set Budgets Early
Section titled “2. Set Budgets Early”# Always have budgetsresource "aws_budgets_budget" "warning" { name = "warning-budget" budget_type = "COST" limit_amount = "5000" limit_unit = "USD" time_unit = "MONTHLY"
notification { threshold = 75 notification_type = "FORECASTED" }}3. Regular Reviews
Section titled “3. Regular Reviews”- Weekly: Review significant changes
- Monthly: Full cost review
- Quarterly: Optimization planning
4. Automate Optimization
Section titled “4. Automate Optimization”# Automated rightsizingdef auto_rightsize(): recommendations = get_rightsize_recommendations()
for rec in recommendations: if rec['SavingsPercentage'] > 20: # Auto-apply for dev environments if rec['Environment'] == 'dev': apply_rightsize(rec)Summary
Section titled “Summary”FinOps enables:
- Visibility: Understand where money is spent
- Optimization: Reduce waste and optimize spend
- Accountability: Teams take ownership of costs
- Governance: Prevent budget overruns
- Planning: Better forecasting and budgeting
Key practices:
- Tagging: Foundation of cost allocation
- Budgets: Alert before overspending
- Rightsizing: Match resources to needs
- Reserved/Spot: Use committed and spot savings
- Automation: Continuous optimization