3 minute read

Cost Prediction banner

Today, most teams catch major cloud cost changes after the bill arrives. Oftentimes this is caught days or weeks later. To help change this, we’re excited to launch the new Kubecost Predict experience to provide forecasted costs before a workload is ever deployed or updated in a Kubernetes environment.

Resource Cost Prediction output

This feature is now available to users running Kubernetes in AWS, GCP, or Azure environments, as well as those with on-prem infrastructure.

Estimating anticipated spending can allow for advanced and accurate Kubernetes budgeting, create visibility to those making changes, and help prevent over-requesting of resources. Kubecost has always provided real-time cost monitoring, but now takes the next step forward with predictive cost metrics.

With the newest release v1.100, Kubecost Predict will analyze everything Kubecost has learned about your environment for accurate estimates. When given a workload spec, Kubecost will produce predictions for these costs and dynamically adapt to reconciliation and other cost modifiers such as private pricing discounts and spot usage. This can be performed simply with a YAML spec of your workload and access to a terminal.

How it works

Kubecost Predict calculates the average cost per resource-hour of resources in the cluster like CPU, RAM, and GPU using Kubecost’s accurate cost monitoring data. It then converts new resources of your workload to resource-hours over the span of a month. Finally, it multiplies the monthly resource-hours of your workload by the cost per resource-hour to arrive at your estimated monthly cost prediction.

The following steps will show you how to use this new functionality with the open source kubectl cost plugin in minutes.

Before you begin

Step 1. Install Kubecost

If you haven’t yet, install Kubecost with the following Helm command:

helm install kubecost cost-analyzer \
--repo https://kubecost.github.io/cost-analyzer/ \
--namespace kubecost --create-namespace \
--set kubecostToken="0qjVaW32o8nsmCAJO0ZSQcFroYXP0b"

Kubecost has alternative install options as well, but Helm is the recommended path.

Step 2. Install kubectl-cost

Also make sure you have kubectl-cost installed before using Kubecost Predict. Kubectl-cost is an open-source kubectl plugin which provides CLI access to your Kubernetes cost monitoring.

Krew

If you have Krew, the kubectl plugin manager, installed: kubectl krew install cost

This is the easiest way to install kubectl cost, but other methods are supported. You can learn more about kubectl-cost in our initial announcement here, or learn more in our docs.

Using Kubecost Predict with kubectl cost

Try it yourself using the following command: kubectl cost predict -f example-workload.yaml

Example output:

+--------------------------------------------+------+-------+-----+------------+------------+-------------+------------+------------+-------------+
| WORKLOAD                                   | CPU  | MEM   | GPU | CPU/MO     | MEM/MO     | GPU/MO      | Δ CPU/MO   | Δ MEM/MO   | TOTAL/MO    |
+--------------------------------------------+------+-------+-----+------------+------------+-------------+------------+------------+-------------+
| default/Deployment/nginx-deployment        | 9    | 6Gi   | 0   | 207.72 USD |  18.54 USD |    0.00 USD | 207.72 USD |  18.54 USD |  226.26 USD |
| kubecost/Deployment/kubecost-cost-analyzer | 15m  | 9Mi   | 0   |   0.35 USD |   0.03 USD |    0.00 USD |  -4.40 USD |  -0.37 USD |    0.37 USD |
| default/Deployment/nginx-deployment-2      | 10   | 35Gi  | 0   | 230.80 USD | 108.15 USD |    0.00 USD | 230.80 USD | 108.15 USD |  338.95 USD |
| default/Pod/nginx-pod                      | 350m | 200Mi | 0   |   8.08 USD |   0.60 USD |    0.00 USD |   8.08 USD |   0.60 USD |    8.68 USD |
| default/Pod/nginx-pod                      | 350m | 200Mi | 3   |   8.08 USD |   0.60 USD | 2080.50 USD |   8.08 USD |   0.60 USD | 2089.18 USD |
+--------------------------------------------+------+-------+-----+------------+------------+-------------+------------+------------+-------------+
|                                            |      |       |     | 455.02 USD | 127.92 USD | 2080.50 USD | 450.28 USD | 127.53 USD | 2663.45 USD |
+--------------------------------------------+------+-------+-----+------------+------------+-------------+------------+------------+-------------+

By default, this shows the expected monthly cost diff. If you want to see total cost, you can run the following example:

kubectl cost predict--no-diff -f second-workload.yaml

+--------------------+-----+-----+-------------+------------+-------------+
| WORKLOAD           | CPU | MEM | CPU/MO      | MEM/MO     | TOTAL/MO    |
+--------------------+-----+-----+-------------+------------+-------------+
| Deployment/example | 9   | 6Gi | 209.51 USD  | 18.73 USD  | 228.24 USD  |
| Deployment/example | 22  | 6Gi | 3115.11 USD | 517.38 USD | 3629.20 USD |
+--------------------+-----+-----+-------------+------------+-------------+

The resulting table provides you resource consumption, monthly cost estimates per resource type, and finally a total monthly cost prediction.

Conclusion

Exposing cost at deploy time is meant to help engineering teams get a sense for expected cost of a change in Kubernetes environments. Providing this awareness allows teams to manage Kubernetes with more predictability and efficiency.

We are just getting started with this functionality, and we will be adding more features and integrations that will make it even more powerful soon! Please reach out to us via email at team@kubecost.com or join us on Slack to request a new feature.

Kubecost is obsessed with providing our users with meaningful insights into their cloud spending, now even before you spend. Ready to take your cost monitoring to the next level? Schedule a demo to see how!