CLI for determining the cost of Kubernetes workloads
CLI for determining the cost of Kubernetes workloads
kubectl-cost is a kubectl plugin
that provides easy CLI access to Kubernetes cost information, like historical cost
and predicted future cost, via Kubecost's APIs. It
allows developers, devops, and others to quickly determine the cost & efficiency
of any Kubernetes workload.
Note: If you use OpenCost, most of
kubectl costworks! See the OpenCost documentation for examples. Let us know how it goes, and open an issue if you encounter any problems!
‼️ New! Starting with Kubecost v1.100, kubectl cost can estimate the cost of undeployed changes! Try it
now with kubectl cost predict -f your-deployment.yaml:
OBJECT Δ QTY RESOURCE UNIT COST PER UNIT Δ COST/MO % CHANGE
────────────────────────────────────────────────────────────────────────────────────────────
kubecost1 deployment -92 CPU millicores 0.023 USD -2.14 USD -92.00%
kubecost1-cost-analyzer
-172.65 RAM MiB 0.0030 USD -0.53 USD -43.38% Install Kubecost
This software requires that you have a running deployment of Kubecost in your cluster. The recommend path is to use Helm but there are alternative install options.
helm repo add kubecost https://kubecost.github.io/cost-analyzer/
helm upgrade -i --create-namespace kubecost kubecost/cost-analyzer --namespace kubecost --set kubecostToken="a3ViZWN0bEBrdWJlY29zdC5jb20=xm343yadf98"Install kubectl cost
If you have Krew, the kubectl plugin manager, installed:
kubectl krew install costThe Krew manifest can be found here.
os=$(uname | tr '[:upper:]' '[:lower:]') && \
arch=$(uname -m | tr '[:upper:]' '[:lower:]' | sed -e s/x86_64/amd64/) && \
curl -s -L https://github.com/kubecost/kubectl-cost/releases/latest/download/kubectl-cost-$os-$arch.tar.gz | tar xz -C /tmp && \
chmod +x /tmp/kubectl-cost && \
sudo mv /tmp/kubectl-cost /usr/local/bin/kubectl-cost If you prefer to download from GitHub, or are on Windows, go to the releases page and download the appropriate binary for your system. Rename it to kubectl-cost and put it in your PATH.
As long as the binary is still named kubectl-cost and is somewhere in your PATH, it will be usable. This is because kubectl automatically finds plugins by looking for executables prefixed with kubectl- in your PATH.
Alternatively, you can view DEVELOPMENT.md if you would like to build from source.
There are several subcommands that focused on aggregation-based cost monitoring:
namespace, deployment, controller, label, pod, and node. They display
cost information aggregated by the name of the subcommand (see Examples). Each
aggregation subcommand has two modes: rate and non-rate. Rate (the default) displays
the projected monthly cost based on the activity during the window. Non-rate
(--historical) displays the total cost for the duration of the window.
Starting with v1.100 installations of Kubecost, kubectl cost predict is
available. It uses historical resource cost information in your cluster to
predict the cost implications of undeployed changes. It currently supports
Pod, Deployment, and StatefulSet workloads, with more support on the way. It
accepts YAML-formatted data either in a file (-f your-file.yaml) or from
STDIN (-f -).
There is also kubectl cost tui, which displays a TUI and is currently limited to
monthly rate projections. It supports most of the above subcommands while in an
experimental status.
See the built-in usage info with --help to learn more about specific flags
available for each subcommand.
Show the projected monthly rate for each namespace with all cost components displayed.
kubectl cost namespace --show-all-resourcesExample output:
…Predict the cost impact of a YAML spec based on its requests:
read -r -d '' DEF If you are running an old version of Kubecost, you may have to replace `tcp-model` with `model`
If that `curl` succeeds, `--use-proxy` flag in CLI or setting up environment variable `KUBECTL_COST_USE_PROXY` should work for you.
Otherwise:
- There may be an underlying problem with your Kubecost install, try `kubectl port-forward`ing the `kubecost-cost-analyzer` service, port 9090, and querying [one of our APIs](https://docs.kubecost.com/apis/apis-overview).
- Your problem could be a security configuration that is preventing the API server communicating with certain namespaces or proxying requests in general.
- If you're still having problems, hit us up on Slack (see below) or open an issue on this repo.
## Requirements
A cluster running Kubernetes version 1.8 or higher
Have questions? Join our [Slack community](https://join.slack.com/t/kubecost/shared_invite/enQtNTA2MjQ1NDUyODE5LWFjYzIzNWE4MDkzMmUyZGU4NjkwMzMyMjIyM2E0NGNmYjExZjBiNjk1YzY5ZDI0ZTNhZDg4NjlkMGRkYzFlZTU) or contact us via email at [[email protected]]([email protected])!No open issues yet, or sync has not completed.