Check Kubernetes Resource Requests, Limits, and Utilization with Kube-capacity CLI

Installation

Go binaries are automatically built with each release by GoReleaser. These can be accessed on the GitHub releases page for this project.

Homebrew

This project can be installed with Homebrew:

brew tap robscott/tap
brew install robscott/tap/kube-capacity

Krew

This project can be installed with Krew:

kubectl krew install resource-capacity

Usage

By default, kube-capacity will output a list of nodes with the total CPU and Memory resource requests and limits for all the pods running on them. For clusters with more than one node, the first line will also include cluster wide totals. That output will look something like this:

Including Pods

For more detailed output, kube-capacity can include pods in the output. When -p or --pods are passed to kube-capacity, it will include pod specific output that looks like this:

Including Utilization

To help understand how resource utilization compares to configured requests and limits, kube-capacity can include utilization metrics in the output. It’s important to note that this output relies on metrics-server functioning correctly in your cluster. When -u or --util are passed to kube-capacity, it will include resource utilization information that looks like this:

kube-capacity --util

Including Pods and Utilization

For more detailed output, kube-capacity can include both pods and resource utilization in the output. When --util and --pods are passed to kube-capacity, it will result in a wide output that looks like this:

kube-capacity --pods --util

Sorting

To highlight the nodes, pods, and containers with the highest metrics, you can sort by a variety of columns:

kube-capacity --util --sort cpu.util

Displaying Pod Count

To display the pod count of each node and the whole cluster, you can pass — pod-count argument:

kube-capacity — pod-count

Filtering By Labels

For more advanced usage, kube-capacity also supports filtering by pod, namespace, and/or node labels. The following examples show how to use these filters:

kube-capacity --pod-labels app=nginx
kube-capacity --namespace default
kube-capacity --namespace-labels team=api
kube-capacity --node-labels kubernetes.io/role=node

JSON and YAML Output

By default, kube-capacity will provide output in a table format. To view this data in JSON or YAML format, the output flag can be used. Here are some sample commands:

kube-capacity --pods --output json
kube-capacity --pods --containers --util --output yaml

Flags Supported

Prerequisites

Any commands requesting cluster utilization are dependent on metrics-server running on your cluster. If it’s not already installed, you can install it with the official helm chart.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Able Lv

Able Lv

Cloud Infrastructure Engineer @Airwallex: Kubernetes, DevOps, Terraform, Istio, Go, and Cloud-Native stuff