LinuxCommandLibrary

kube-capacity

Show cluster resource requests, limits, and utilization

TLDR

List nodes including the total CPU and Memory resource requests and limits

$ kube-capacity
copy

Include pods
$ kube-capacity [[-p|--pods]]
copy

Include utilization
$ kube-capacity [[-u|--util]]
copy

SYNOPSIS

kube-capacity [options]
kube-capacity --output format
kube-capacity --sort field

PARAMETERS

--output
    Specifies the output format. Supported values: table (default), json, yaml.

--sort
    Sorts the output by a specific field. Examples include cpu.request, memory.limit, or cpu.utilization.

--utilization
    If present, calculates and displays resource utilization percentage (requests vs. current usage). Requires metrics-server in the cluster.

--pods
    Includes individual pod resource requests/limits and usage in the output.

--containers
    Includes individual container resource requests/limits and usage in the output. This option implies --pods.

--namespaces
    Aggregates and groups the output by Kubernetes namespace.

--nodes
    Aggregates and groups the output by Kubernetes node.

--all-namespaces
    Includes resources from all namespaces in the cluster.

--namespace
    Filters the output to include resources only from the specified namespace(s). Can be used multiple times.

--exclude-system-namespaces
    Excludes the kube-system and kube-public namespaces from the output.

--kubeconfig
    Path to the kubeconfig file to use for connecting to the Kubernetes API.

--context
    The name of the kubeconfig context to use for the Kubernetes API connection.

--verbose
    Enables verbose output for more detailed information.

DESCRIPTION

kube-capacity is a command-line interface (CLI) tool designed to provide a clear and concise overview of resource requests, limits, and current usage within a Kubernetes cluster. It helps administrators and developers understand how effectively resources (CPU and memory) are allocated across nodes, namespaces, and pods.

By aggregating data from the Kubernetes API, kube-capacity enables users to quickly identify potential resource overcommitments, underutilization, or bottlenecks, aiding in capacity planning and troubleshooting. It presents a tabular view of resource consumption, making it easier to visualize the cluster's overall health and resource distribution. This tool is invaluable for ensuring optimal resource management and preventing performance issues in production Kubernetes environments.

CAVEATS

kube-capacity requires kubectl to be properly configured and connected to a Kubernetes cluster.
Resource utilization data (shown with --utilization) depends on the presence and proper functioning of metrics-server in your cluster; if not available, utilization values may appear as 0 or N/A.
The tool provides a snapshot of current resource states and does not offer historical data or trend analysis.
Frequent execution on very large clusters might incur significant Kubernetes API calls, potentially hitting API rate limits.

INSTALLATION

As kube-capacity is an external utility, it needs to be installed separately. Common installation methods include:
Homebrew (macOS/Linux): Use `brew install robscott/tap/kube-capacity`.
Krew (kubectl plugin manager): Use `kubectl krew install capacity`.
Direct Download: Download the pre-compiled binary from its GitHub releases page and add it to your system's PATH.

TYPICAL USE CASES

kube-capacity is highly useful for:
Capacity Planning: Understanding current resource usage to plan for future cluster growth.
Troubleshooting: Identifying pods or nodes that are requesting excessive resources or are underutilized.
Cost Optimization: Pinpointing opportunities to right-size resource requests and limits to reduce cloud infrastructure costs.
Resource Governance: Ensuring teams are adhering to resource allocation policies across namespaces.

HISTORY

kube-capacity is an open-source, community-driven utility, not a native Kubernetes command. It was developed to address the need for a comprehensive, cluster-wide view of resource allocation and usage, which was not readily available through standard kubectl commands. Its development is maintained by a community of contributors, continually adding features and improving its analytical capabilities.

SEE ALSO

kubectl top(1), kubectl describe(1)

Copied to clipboard