Skip to content

Automatically scale LXC containers resources on Proxmox hosts

License

Notifications You must be signed in to change notification settings

fabriziosalmi/proxmox-lxc-autoscale

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

641 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

LXC AutoScale

LXC AutoScale is a resource management daemon for Proxmox environments. It automatically adjusts CPU and memory allocations for LXC containers based on real-time usage metrics and predefined thresholds. It can run locally on the Proxmox host or connect remotely via SSH. Container cloning (horizontal scaling) is also supported as an experimental feature.

  • Tested with Proxmox 8.3.3

Quick Start

Method Instructions
Docker Docker
No Docker Install script

Features

  • Automatic vertical scaling of CPU cores and memory based on usage thresholds
  • Horizontal scaling via container cloning (experimental)
  • Per-container or per-group threshold configuration using tiers
  • Host CPU and memory reservation to prevent over-allocation
  • Container exclusion list (ignore_lxc)
  • Energy efficiency mode that reduces resources during off-peak hours
  • Container prioritization via tier configuration
  • Automatic backups of container settings before changes
  • Notifications via email (SMTP), Gotify, and Uptime Kuma
  • JSON metrics log alongside the plain-text log
  • Local execution or remote execution via SSH
  • Auto-configuration script for generating initial YAML config
  • Docker support for running the daemon in a container

Note

If you need to autoscale Virtual Machine resources on Proxmox hosts, you will like this project.

Quick Start

Prerequisites

  • Proxmox VE 8.x (tested with 8.3.3)
  • Python 3.6+
  • Root access to the Proxmox host
  • LXC containers already created and configured
  • Internet connection for downloading the installation script

Important

LXC AutoScale requires LXCFS to be properly configured. See the LXCFS configuration section below for details.

Installation

curl -sSL https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/install.sh | bash

Tip

Once installed, verify the service is running:

systemctl status lxc_autoscale.service

LXCFS Configuration (Important)

Important

You need to check your /lib/systemd/system/lxcfs.service file for the presence of the -l option which makes loadavg retrieval work as expected. Here is the required configuration:

[Unit]
Description=FUSE filesystem for LXC
ConditionVirtualization=!container
Before=lxc.service
Documentation=man:lxcfs(1)

[Service]
OOMScoreAdjust=-1000
ExecStartPre=/bin/mkdir -p /var/lib/lxcfs
# ExecStart=/usr/bin/lxcfs /var/lib/lxcfs
ExecStart=/usr/bin/lxcfs /var/lib/lxcfs -l
KillMode=process
Restart=on-failure
ExecStopPost=-/bin/fusermount -u /var/lib/lxcfs
Delegate=yes
ExecReload=/bin/kill -USR1 $MAINPID

[Install]
WantedBy=multi-user.target

Just update the /lib/systemd/system/lxcfs.service file, execute systemctl daemon-reload && systemctl restart lxcfs, and when you are ready to apply the fix, restart the LXC containers.

Thanks to No-Pen9082 for pointing this out. Here is the Proxmox forum thread on the topic.

Configuration

LXC AutoScale is configured via a YAML file at /etc/lxc_autoscale/lxc_autoscale.yaml. For detailed configuration options, see the documentation.

Tip

If you need LXC AutoScale configuration for all your LXC containers, you can automatically generate it by running this command:

curl -sSL https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale/lxc_autoscale_autoconf.sh | bash

Additional Resources

Tip

LXC AutoScale ML has been moved to a separate repository.

Frequently Asked Questions

Can I use this on Proxmox 7.x?

LXC AutoScale is tested on Proxmox VE 8.3.3. It may work on older versions, but compatibility is not guaranteed.

Will this work with my existing containers?

Yes. Configure the container IDs in the YAML file and the service will start managing them.

Does this support virtual machines (VMs)?

No, LXC AutoScale is designed for LXC containers only. For VM autoscaling, see proxmox-vm-autoscale.

Can I run this remotely?

Yes. Set use_remote_proxmox: true in the configuration and provide SSH credentials (ssh_user, ssh_password or ssh_key_path, proxmox_host, ssh_port).

Is it safe to use in production?

LXC AutoScale backs up container settings before making changes and supports rollback via --rollback. Test thoroughly in a non-production environment before deploying to production.

How often does it check container resources?

The default polling interval is 300 seconds (5 minutes). Adjust with the poll_interval setting.

Can I exclude certain containers from autoscaling?

Yes. Add container IDs to the ignore_lxc list in the configuration file.

For more detailed questions and answers, see the Q&A documentation.

Contributing

Contributions are welcome. To get involved:

  • Open an issue to report bugs or request features.
  • Submit a pull request.
  • Fork the repository to develop custom features.

Other Projects

If you like this project, you may also like these:

  • caddy-waf Caddy WAF (Regex Rules, IP and DNS filtering, Rate Limiting, GeoIP, Tor, Anomaly Detection)
  • patterns Automated OWASP CRS and Bad Bot Detection for Nginx, Apache, Traefik and HaProxy
  • blacklists Hourly updated domains blacklist 🚫
  • proxmox-vm-autoscale Automatically scale virtual machines resources on Proxmox hosts
  • UglyFeed Retrieve, aggregate, filter, evaluate, rewrite and serve RSS feeds using Large Language Models for fun, research and learning purposes
  • DevGPT Code together, right now! GPT powered code assistant to build project in minutes
  • websites-monitor Websites monitoring via GitHub Actions (expiration, security, performances, privacy, SEO)
  • caddy-mib Track and ban client IPs generating repetitive errors on Caddy
  • zonecontrol Cloudflare Zones Settings Automation using GitHub Actions
  • lws linux (containers) web services
  • cf-box cf-box is a set of Python tools to play with API and multiple Cloudflare accounts.
  • limits Automated rate limits implementation for web servers
  • dnscontrol-actions Automate DNS updates and rollbacks across multiple providers using DNSControl and GitHub Actions
  • proxmox-lxc-autoscale-ml Automatically scale the LXC containers resources on Proxmox hosts with AI
  • csv-anonymizer CSV fuzzer/anonymizer
  • iamnotacoder AI code generation and improvement

Disclaimer

Caution

The author assumes no responsibility for any damage or issues that may arise from using this tool.

License

LXC AutoScale is licensed under the MIT License, which means you are free to use, modify, and distribute this software with proper attribution. For more details, please see the LICENSE file.