A simple go tool, that calculates the allocated resources from all nodes matching the label selector.

kube-allocated-resources

This is a simple go tool, that calculates the allocated resources from all nodes matching the label selector.

Build

Build on Linux to run on Linux:

go build -o kube-allocated-resources

Build on Mac to run on Linux:

GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -o kube-allocated-resources

Usage

./kube-allocated-resources -h

Usage of ./kube-allocated-resources:
  -d	Return node details
  -g	Return totals grouped by the instance type
  -l string
    	Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2) (default "servicecomponent=workernode")
  -o string
    	Output format. One of: json or yaml (default "json")

Examples

Get the to allocated resources from all nodes matching the label selector

./kube-allocated-resources -l node-role.kubernetes.io/worker="",node.kubernetes.io/instance-type=m5.2xlarge -o json| jq

Output:

{
  "totals": {
    "node_count": 39,
    "cpu_requests": 225652,
    "cpu_requests_percentage": 72,
    "cpu_limits": 666195,
    "cpu_limits_percentage": 213,
    "cpu_total": 312000,
    "memory_requests": 481475656192,
    "memory_requests_percentage": 37,
    "memory_limits": 940615522048,
    "memory_limits_percentage": 72,
    "memory_total": 1291281694720,
    "pods_allocated": 1692,
    "pods_total": 9750,
    "pods_allocated_percentage": 17
  }
}

Get the to allocated resources from nodes matching the label selector detailed per node

./kube-allocated-resources -l node-role.kubernetes.io/worker="" -o json -d | jq

Output:

{
  "totals": {
    "node_count": 45,
    "cpu_requests": 273755,
    "cpu_requests_percentage": 65,
    "cpu_limits": 766395,
    "cpu_limits_percentage": 182,
    "cpu_total": 420000,
    "memory_requests": 543121211136,
    "memory_requests_percentage": 30,
    "memory_limits": 1090504162048,
    "memory_limits_percentage": 60,
    "memory_total": 1791866646528,
    "pods_allocated": 1839,
    "pods_total": 11250,
    "pods_allocated_percentage": 16
  },
  "nodes": [
    {
      "node_name": "ip-10-30-46-119.ec2.internal",
      "instance_type": "m5.2xlarge",
      "cpu_requests": 5959,
      "cpu_requests_percentage": 74.4875,
      "cpu_limits": 10300,
      "cpu_limits_percentage": 128.75,
      "cpu_total": 8000,
      "memory_requests": 9690939392,
      "memory_requests_percentage": 29.16565788753514,
      "memory_limits": 14728298496,
      "memory_limits_percentage": 44.32599336597258,
      "memory_total": 33227227136,
      "pods_allocated": 30,
      "pods_total": 250,
      "pods_allocated_percentage": 12
    },
    ...
  ]
}

Get the to allocated resources from nodes matching the label selector grouped by the instance type

./kube-allocated-resources -l node-role.kubernetes.io/worker="" -o json -g | jq

Output:

{
  "totals": {
    "node_count": 45,
    "cpu_requests": 273830,
    "cpu_requests_percentage": 65,
    "cpu_limits": 767895,
    "cpu_limits_percentage": 182,
    "cpu_total": 420000,
    "memory_requests": 544731823872,
    "memory_requests_percentage": 30,
    "memory_limits": 1092114774784,
    "memory_limits_percentage": 60,
    "memory_total": 1791866646528,
    "pods_allocated": 1842,
    "pods_total": 11250,
    "pods_allocated_percentage": 16
  },
  "groupedby_instance_type": [
    {
      "node_count": 3,
      "instance_type": "m5.8xlarge",
      "cpu_requests": 44992,
      "cpu_requests_percentage": 46,
      "cpu_limits": 94200,
      "cpu_limits_percentage": 98,
      "cpu_total": 96000,
      "memory_requests": 53357510656,
      "memory_requests_percentage": 13,
      "memory_limits": 146569700352,
      "memory_limits_percentage": 36,
      "memory_total": 400900472832,
      "pods_allocated": 60,
      "pods_total": 750,
      "pods_allocated_percentage": 8
    },
    {
      "node_count": 39,
      "instance_type": "m5.2xlarge",
      "cpu_requests": 224717,
      "cpu_requests_percentage": 72,
      "cpu_limits": 667695,
      "cpu_limits_percentage": 214,
      "cpu_total": 312000,
      "memory_requests": 479615581952,
      "memory_requests_percentage": 37,
      "memory_limits": 939253618432,
      "memory_limits_percentage": 72,
      "memory_total": 1291281694720,
      "pods_allocated": 1696,
      "pods_total": 9750,
      "pods_allocated_percentage": 17
    },
    {
      "node_count": 3,
      "instance_type": "r5.xlarge",
      "cpu_requests": 4121,
      "cpu_requests_percentage": 34,
      "cpu_limits": 6000,
      "cpu_limits_percentage": 50,
      "cpu_total": 12000,
      "memory_requests": 11758731264,
      "memory_requests_percentage": 11,
      "memory_limits": 6291456000,
      "memory_limits_percentage": 6,
      "memory_total": 99684478976,
      "pods_allocated": 86,
      "pods_total": 750,
      "pods_allocated_percentage": 11
    }
  ]
}

JQ query examples

Get tab delimited values

./kube-allocated-resources -l node-role.kubernetes.io/worker="",node.kubernetes.io/instance-type=m5.8xlarge -o json | jq -r '[
	.totals.cpu_total,
	.totals.cpu_requests
] | @tsv'

Output:

96000	44992

Do some math

./kube-allocated-resources -l node-role.kubernetes.io/worker="",node.kubernetes.io/instance-type=m5.8xlarge -o json -d | jq -r '. | [
        reduce .nodes[].cpu_total as $num (0; .+$num),
        reduce .nodes[].cpu_requests as $num (0; .+$num)
        ] | @tsv'

Output:

96000	44992
Similar Resources

A CoreDNS plugin to create records for Kubernetes nodes.

kubenodes Name kubenodes - creates records for Kubernetes nodes. Description kubenodes watches the Kubernetes API and synthesizes A, AAAA, and PTR rec

Jul 7, 2022

Manages nodes in hybrid k8s self-hosted cluster

node-manager Manages nodes in hybrid k8s self-hosted cluster Supported providers Contabo Hetzner Robot (dedicated) Supported commands Heal - reboots a

Dec 23, 2021

Rqlite-recover - k8 controller to create recover json for rqlite cluster nodes when needed.

Cluster Recover for RQLite running on a k8s cluster The goal is to be able to recover a rqlite cluster when the majority of nodes get re-schedule to d

Sep 8, 2022

K8s-delete-protection - Kubernetes admission controller to avoid deleteing master nodes

k8s-delete-protection Admission Controller If you want to make your Kubernetes c

Nov 2, 2022

A tool to bring existing Azure resources under Terraform's management

Azure Terrafy A tool to bring your existing Azure resources under the management of Terraform. Install go install github.com/magodo/aztfy@latest Usage

Dec 9, 2021

A tool to bring existing Azure resources under Terraform's management

Azure Terrafy A tool to bring your existing Azure resources under the management of Terraform. Goal Azure Terrafy imports the resources inside a resou

Jan 1, 2023

Vilicus is an open source tool that orchestrates security scans of container images(docker/oci) and centralizes all results into a database for further analysis and metrics.

Vilicus is an open source tool that orchestrates security scans of container images(docker/oci) and centralizes all results into a database for further analysis and metrics.

Vilicus Table of Contents Overview How does it work? Architecture Development Run deployment manually Usage Example of analysis Overview Vilicus is an

Dec 6, 2022

OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)

OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)

Terraform Provider OpenAPI This terraform provider aims to minimise as much as possible the efforts needed from service providers to create and mainta

Dec 26, 2022

A kubernetes plugin which enables dynamically add or remove GPU resources for a running Pod

A kubernetes plugin which enables dynamically add or remove GPU resources for a running Pod

GPU Mounter GPU Mounter is a kubernetes plugin which enables add or remove GPU resources for running Pods. This Introduction(In Chinese) is recommende

Jan 5, 2023
Ducklett: managing all the little nodes of a Conducktor cluster

Ducklett Overview Ducklett is a kubernetes controller that manages updating nodes in a Conducktor cluster. Origin For immutable infrastructure, we nee

Nov 14, 2022
Drone plugin to create comment and label in PR to Gitee
Drone plugin to create comment and label in PR to Gitee

drone-plugin-gitee-pulls 中文文档 Drone plugin to create comment and label in PR to

Sep 6, 2022
A golang tool to list out all EKS clusters with active nodegroups in all regions in json format

eks-tool A quick and dirty tool to list out all EKS clusters with active nodegro

Dec 18, 2021
Enforcing per team quota (sum of used resources across all their namespaces) and delegating the per namespace quota to users.

Quota Operator Enforcing per team quota (sum of used resources across all their namespaces) and delegating the per namespace quota to users. Instructi

Nov 9, 2022
Act is a task runner and supervisor with some great features like act name matching, subacts, etc. We use this in nosebit workspaces.

Act Act is a task runner and supervisor tool written in Go which aims to provide the following features: process supervision in a project level allow

May 8, 2022
Simple tool to move Azure resources based on Terraform state

aztfmove Simple tool to move Azure resources based on Terraform state Goal It is sometimes inevitable to move Azure resources to a new subscription or

Dec 29, 2022
Kubei is a flexible Kubernetes runtime scanner, scanning images of worker and Kubernetes nodes providing accurate vulnerabilities assessment, for more information checkout:
Kubei is a flexible Kubernetes runtime scanner, scanning images of worker and Kubernetes nodes providing accurate vulnerabilities assessment, for more information checkout:

Kubei is a vulnerabilities scanning and CIS Docker benchmark tool that allows users to get an accurate and immediate risk assessment of their kubernet

Dec 30, 2022
A prometheus exporter for monitoring FIO nodeos nodes.
A prometheus exporter for monitoring FIO nodeos nodes.

fio-prometheus-exporter This is a simple prometheus exporter for FIO nodeos nodes. It can connect to multiple nodes to display a few critical statisti

Aug 19, 2022
Latest block exporter to monitor your own nodes !

Ethereum Block Prometheus Exporter Deeply copied from 31z4/ethereum-prometheus-exporter Thanks a lot for his work ! This service exports the latest bl

Nov 5, 2021
Viewnode displays Kubernetes cluster nodes with their pods and containers.

viewnode The viewnode shows Kubernetes cluster nodes with their pods and containers. It is very useful when you need to monitor multiple resources suc

Nov 23, 2022