Title: Building a 5 node Proxmox cluster!
Date: 2024-07-24 20:00
Modified: 2024-07-24 20:00
Category: Server Architecture
Tags: proxmox, kubernetes, hardware
Slug: proxmox-cluster-1
Authors: Andrew Ridgway
Summary: Upgrade from a small docker-compose style server to full proxmox server with kubernetes, LXC, and a hypervisor

#### A quick summary of this post by AI

I'm going to use AI to summarise this post here because it ended up quite long I've edited it ;) 

**Summary:**

Quick look at some of the things I've used Proxmox fr

* I've set up LXC containers for various services like Plex, databases (PostgreSQL, MySQL, MongoDB), Nginx, and file serving, taking advantage of Proxmox's ease of use and integration with standard Linux tools.
* I'm using QEMU-based virtual machines (VMs) sparingly due to resource concerns, but have set up a simple Kubernetes cluster across three nodes (Intel NUCs) using VMs. Additionally, you have a development VM for remote coding environments.
* My current plans include writing about your Kubernetes setup, Gitea CI/CD pipelines, and other tools like n8n, Grafana, and Matrix.

As part of the summary it came up with this interesting idea of "follow up" I'm leaving it here as I thought it was an interesting take on what I can write about in the future

**Follow-up Questions:**

1. **Kubernetes Cluster:**
   * What challenges did you face while setting up your Kubernetes cluster with k3s and Longhorn? How did you troubleshoot and eventually stabilize the system?
   * How have you configured resource allocation for your Kubernetes nodes to balance performance and efficiency?

2. **CI/CD with Gitea:**
   * Can you provide more details on how you're integrating LXC containers with your Gitea CI/CD pipelines? What steps are involved in setting up this process?
   * What triggers deployments or builds in your CI/CD setup, and how do you handle failures or errors?

3. **Monitoring and Logging:**
   * How have you configured monitoring and logging for your Proxmox setup? Are you using tools like Prometheus, Grafana, or others to keep track of your systems' health?
   * How do you ensure the security and privacy of your data while utilizing these tools?

4. **Future Plans:**
   * You mentioned exploring the idea of having Mistral AI write blog posts based on your notes. Can you elaborate more on this concept? What challenges might arise, and how do you plan to address them?
   * Are there any other new technologies or projects you're considering for your homelab in the near future?


## A Picture is worth a thousand words
<img alt="Proxmox Image" height="auto" width="100%" src="{attach}/images/proxmox.jpg">

_Yes I know the setup is a bit hacky but it works. Below is an image of the original architecture its changed a bit but you sort of get what's going on_

<img alt="Proxmox Architecture" height="auto" width="100%" src="{attach}/images/Server_Initial_Architecture.png">

## The idea
For some time now I have been toying with the idea of a hypervisor. Initially my thoughts were to get some old blade servers and use those. That was until someone pointed out there power requirements. Looking at specs for some of these machines the power supplies would be 600 to 800 watts, which is fine until you realise that these have redundant powersupplies and are now potentially pulling up 1.5kW of energy... I'm not made of money!

I eventually decided I'd use some hardware I had already lying around, including the old server, as well as 3 Old Intel Nuc I could pick up for under $100 (4th gen core i5's upgraded to 16GB RAM DDR3). I'd also use an old Dell Workstation I had lying around to provide space for some storage, it currently has 4TB RAID 1 on BTRFS sharing via NFS.

All together the 5 machines draw less that 600W of power, cool, hardware sorted (at least for a little hobby cluster)

### The platform for the Idea!
After doing some amazing reddit research and looking at various homelab ideas for doing what I wanted it became very very clear the proxmx was going to the solution. Its a debian based, open source hypervisor that, for the cost of an annoying little nag when you log in and some manual deb repo congif, gives you an enterprise grade hypervisor ready to spin up VM's and "LXC's" or Linux Jails...These have turned out to be really really useful but more on that later.

First lets define what on earth Proxmox is

#### Proxmox
Proxmox VE (Virtual Environment) is an open-source server virtualization platform that has gained significant popularity among home lab enthusiasts due to its robustness, ease of use, and impressive feature set. Here's why Proxmox stands out as a fantastic choice for homelab clusters:

1. **Simultaneous Management of LXC Containers and VMs:**
   Proxmox VE allows you to manage both Linux Container (LXC) guests and Virtual Machines (VMs) under a single, intuitive web interface or via the command line. This makes it incredibly convenient to run diverse workloads on your homelab cluster.

   For instance, you might use LXC containers for lightweight tasks like web servers, mail servers, or development environments due to their low overhead and fast start-up times. Meanwhile, VMs are perfect for heavier workloads that require more resources or require full system isolation, such as database servers or Windows-based applications.

2. **Efficient Resource Allocation:**
   Proxmox VE provides fine-grained control over resource allocation, allowing you to specify resource limits (CPU, memory, disk I/O) for both LXC containers and VMs on a per-guest basis. This ensures that your resources are used efficiently, even when running mixed workloads.

3. **Live Migration:**
   One of the standout features of Proxmox VE is its support for live migration of both LXC containers and VMs between nodes in your cluster. This enables you to balance workloads dynamically, perform maintenance tasks without downtime, and make the most out of your hardware resources.

4. **High Availability:**
   The built-in high availability feature allows you to set up automatic failover for your critical services running as LXC containers or VMs. In case of a node failure, Proxmox VE will automatically migrate the guests to another node in the cluster, ensuring minimal downtime.

5. **Open-Source and Free:**
   Being open-source and free (with optional paid support), Proxmox VE is an attractive choice for budget-conscious home lab enthusiasts who want to explore server virtualization without breaking the bank. It also offers a large community of users and developers, ensuring continuous improvement and innovation.

Proxmox VE is an incredibly useful platform for homelab clusters due to its ability to manage both LXC containers and VMs efficiently, along with its advanced features like live migration and high availability. Whether you're looking to run diverse workloads or experiment with virtualization technologies, Proxmox VE is definitely worth considering.

**Relevant Links:**

- Official Proxmox VE website: <https://www.proxmox.com/>

- Proxmox VE documentation: <https://pve-proxmox-community.org/>

- Proxmox VE forums: <https://forum.proxmox.com/>

I'd like to thank the mistral-nemo LLM for writing that ;) 

### LXC's

To start to understand proxmox we do need to focus in on one important piece, LXC's these are containers but not docker container, below I've had mistral summarise some of the differences.

**Isolation Level**:

- LXC uses Linux's built-in features like cgroups and namespaces for containerization. This provides a high degree of isolation between containers.
   
- Docker also uses these features but it adds an additional layer called the "Docker Engine" which manages many aspects of the containers, including networking, storage, etc.

**System Call Filtering**:

- LXC does not have system call filtering by default. This means that processes inside LXC containers can make any syscall available on the host.

- Docker provides system call filtering with its "rootless" mode or using a tool like AppArmor, which restricts the capabilities of processes running in containers.

**Resource Management**

- LXC has built-in support for cgroup hierarchy management and does not enforce strict limits by default.

- Docker enforces strict resource limits on every container by default.

**Networking**:

- In LXC, each container gets its own network namespace but IP addresses are shared by default. Networking is managed using traditional Linux tools like `ip` or `bridge-utils`.

- Docker provides a custom networking model with features like user-defined networks, service discovery, and automatic swarm mode integration.

What LXC is Focused On:

Given these differences, here's what LXC primarily focuses on:

1. **Simplicity and Lightweightness**: LXC aims to provide a lightweight containerization solution by utilizing only Linux's built-in features with minimal overhead. This makes it appealing for systems where resource usage needs to be kept at a minimum.

2. **Control and Flexibility**: By not adding an extra layer like Docker Engine, LXC gives users more direct control over their containers. This can make it easier to manage complex setups or integrate with other tools.

3. **Integration with Traditional Linux Tools**: Since LXC uses standard Linux tools for networking (like `ip` and `bridge-utils`) and does not add its own layer, it integrates well with traditional Linux systems administration practices.

4. **Use Cases Where Fine-grained Control is Required**: Because of its flexible nature, LXC can be useful in scenarios where fine-grained control over containerization is required. For example, in scientific computing clusters or high-performance computing environments where every bit of performance matters.

So, while Docker provides a more polished and feature-rich container ecosystem, LXC offers a simple, lightweight, and flexible alternative for those who prefer to have more direct control over their containers and prefer using standard Linux tools.

Ever since I discovered Proxmox LXC containers, my server management has been a breeze. For my Plex setup, it's perfect - isolating each instance and keeping resources in check but by using device loading I can get a graphics card there for some sweet sweet hardware decoding. Same goes for my databases; PostgreSQL, MySQL, and MongoDB all run smoothly as individual LXCs. Nginx, too, has found its home here, handling reverse proxy duties without breaking a sweat. And for fileservering, what could be better than having a dedicated LXC for that? It's like having my own little server farm right at my fingertips!

The LXC's have also been super easy to set up with the help of ttecks helper scripts [Proxmox Helper Scripts](https://community-scripts.github.io/Proxmox/) It was very sad to hear he had gotten [sick](https://www.reddit.com/r/Proxmox/comments/1gk19gm/ttecks_proxmoxve_helper_scripts_changes/) and I realy hope he gets well soon!

### VM's 

Proxmox uses the open-source QEMU hypervisor for hardware virtualization, enabling it to create and manage multiple isolated virtual machines on a single physical host. QEMU, which stands for Quick Emulator, is full system emulator that can run different operating systems directly on a host machine's hardware. When used in conjunction with Proxmox's built-in web-based interface and clustering capabilities, QEMU provides numerous advantages for VM management. These include live migration of running VMs between nodes without downtime, efficient resource allocation due to QEMU's lightweight nature, support for both KVM (Kernel-based Virtual Machine) full virtualization and hardware-assisted virtualization technologies like Intel VT-x or AMD-V, and the ability to manage and monitor VMs through Proxmox's intuitive web interface. Additionally, QEMU's open-source nature allows Proxmox users to leverage a large community of developers for ongoing improvements and troubleshooting!

Again I'd like to thank mistral-nemo for that very informative piece of prose ;) 

The big question here is what do I use the VM capablity of Proxmox for?

I actually try to avoid their use as I don't want the massive use of resources, however, part of the hardware design I came up with was to use the 3 Old Intel Nuc's as predominately a kubernetes cluster.. and so I have 3 Vm's spread across those nodes that act as my very simple Kubernetes cluster I also have a VM I turn on and off as required that can act as a development machine and gives me remote VS Code or Zed environments. (I look forward to writing a blog post on Zed and How that's gone for me)

I do look forward to writing a seperate post about how the kubernetes cluster has gone. I have used k3s and longhorn and it hasn't been a rosy picture, but after a couple months I finally seem to have landed on a stable system

Anyways, Hopefully this gives a pretty quick overview of my new cluster and some of the technologies it uses. I hope to write a post in the future about the gitea CI/CD I have set up that leverages kubernetes and LXC's to get deployment pipelines as well as some of the things I'm using n8n, grafana and matrix for but I think for right now myself and mistral need to sign off and get posting. 

Thanks for reading this suprisingly long post (if you got here) and I look forward to upating you on some of the other cool things I'm experimenting with with this new homelab. (Including an idea I'm starting to form of having my mistral instance actually start to write some blogs on this site using notes I write so that my posting can increase.. but I need to experiment with that a bit more)
