Skip to content

Very crude and coarse node_balancer for quick balancing memory across clusters with missing or wrong resource requests. Use are your own risk!

License

Notifications You must be signed in to change notification settings

silashansen/k8s_nodebalancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memory Balancer

This script balances the memory usage between nodes in a Kubernetes cluster by moving pods from nodes with high memory usage to nodes with low memory usage. The routine will keep moving pods until the highest and lowest memory usage are within the defined threshold.

Note: This script is very brutal and will move any pods by brutally deleting, without paying attention to deployment strategies or similar.

Node Groups

In the node_groups.json file, you MUST define the node groups you want to balance. (Will add the ability to select groups based on node labels in the future.)

{
    "controlplane": [
        "master-1",
        "master-2",
        "master-3"
    ],
    "non-production": [
        "worker-1",
        "worker-2",
        "worker-3",
        "worker-4",
        "worker-5"
    ],
    "production": [
        "worker-6",
        "worker-7"
    ]
}

directory structure

.
├── kubernetes
│   ├── client.py
│   ├── node_manager.py
│   └── pod_manager.py
├── utils
│   ├── resource_utils.py
├── nodes.json
├── balancer.py
├── main.py
└── README.md

Requirements

  • Python 3.10+
  • kubectl in the current PATH

How to run

To balance the nodes once the difference between the highest and lowest memory usage is greater than 10%:

python3 main.py [-h] [--threshold THRESHOLD] [--dry-run] node_group

positional arguments:
  node_group            Node group to balance. Available groups: <groups_in_node_groups.json>

options:
  -h, --help            show this help message and exit
  --threshold, -t THRESHOLD
                        Threshold for node balancing (default: 10)
  --dry-run, -d         Perform a dry run without making actual changes

Example

python3 main.py --dry-run --threshold 10 non-production

About

Very crude and coarse node_balancer for quick balancing memory across clusters with missing or wrong resource requests. Use are your own risk!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages