Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pattern): Kubecost with AWS CUR Report #1862

Merged
merged 20 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions patterns/kubecost/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
crawler-cfn.yml
64 changes: 64 additions & 0 deletions patterns/kubecost/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Kubecost with AWS Cloud Billing Integration

This pattern demostrates how to install and configure Kubecost with AWS CUR report.
The terraform code was created following the official Kubecost documentation for [aws cloud billing integration](https://docs.kubecost.com/install-and-configure/install/cloud-integration/aws-cloud-integrations).

## Prerequisites

You need a valid Kubecost token. To generate one, follow the instructions [here](https://www.kubecost.com/install#show-instructions).


# Deploy
```
terraform init
terraform apply -target="module.vpc" -auto-approve
terraform apply -target="module.eks" -auto-approve
terraform apply -auto-approve --var="kubecost_token=<your-kubecost-token>"
```

Once all of the resources have successfully been provisioned, the following command can be used to update the `kubeconfig` on your local machine and allow you to interact with your EKS Cluster using `kubectl`.

```
aws eks --region <REGION> update-kubeconfig --name <CLUSTER_NAME>
```

This command will create a S3 bucket with prefix `kubecost-` and a Cost and Usage Report (CUR). Within 24h The CUR will generate a CloudFormation teamplate file called `crawler-cfn.yml` in the S3 bucket. Once that file is generated, navigate to:

```
cd run-me-in-24h/
```
To download and apply the CloudFormation template, run:
```
terraform init
terraform apply --auto-approve
```

## Kubecost UI
To access the Kubecost UI run:
```
echo http://$(kubectl -n kubecost get svc cost-analyzer-cost-analyzer -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'):9090/
```
and navigate to the output URL.

Navigate to Settings -> Diagnostics -> View Full Diagnostics

Expected result:
![screenshot](static/screenshot.png)

> [!NOTE]
> Spot Data Feed is included in Savings Plan, Reserved Instance, and Out-Of-Cluster.

## Destroy
First destroy the CloudFormation template:
```
cd run-me-in-24h/
terraform destroy --auto-approve
```

```
cd ..
terraform destroy -target="module.eks_blueprints_addon" --var="kubecost_token=<your-kubecost-token>" -auto-approve
terraform destroy -target="module.eks_blueprints_addons"
terraform destroy -target="module.eks" -auto-approve
terraform destroy -auto-approve
```
32 changes: 32 additions & 0 deletions patterns/kubecost/kubecost-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
kubecostToken: ${kubecostToken}

global:
grafana:
enabled: false
proxy: false

serviceAccount:
create: true
name: ${service-account}
annotations:
eks.amazonaws.com/role-arn: ${iam-role-arn}

service:
type: LoadBalancer
port: 9090
targetPort: 9090
labels: {}
annotations: {}
sessionAffinity:
enabled: false # Makes sure that connections from a client are passed to the same Pod each time, when set to `true`. You should set it when you enabled authentication through OIDC or SAML integration.
timeoutSeconds: 10800

kubecostProductConfigs:
projectID: ${projectID}
spotLabel: eks.amazonaws.com/capacityType
spotLabelValue: SPOT
athenaProjectID: ${athenaProjectID}
athenaBucketName: ${athenaBucketName}
athenaRegion: ${athenaRegion}
athenaDatabase: ${athenaDatabase}
athenaTable: ${athenaTable}
Loading
Loading