DEV Community

Cover image for Automating Production-grade multi-node Kubernetes with KUBESPRAY on multipass with Just a single command
George Ezejiofor
George Ezejiofor

Posted on • Originally published at georgeezejiofor.com

Automating Production-grade multi-node Kubernetes with KUBESPRAY on multipass with Just a single command

Introduction
Are you overwhelmed by the complexity of deploying production-grade multi-node Kubernetes clusters? 😅 The countless configurations, the manual setup, and the inevitable errors—it’s enough to make anyone feel like giving up! But what if I told you there’s a way to automate the entire process with just one command? 🤯 Just like the way you do terraform apply -auto-approve and terraform destroy -auto-approve.

Imagine deploying a robust, scalable, and production-ready Kubernetes cluster as effortlessly as running a simple script. ✨ With the power of Kubespray and Multipass, I’ve developed an automated solution that does exactly that! 🚀

Here’s how it works:

Cluster Deployment: A single command, python3 terranetes.py cluster init provisions a multi-node Kubernetes cluster using Kubespray on Multipass. No manual intervention is needed! 🛠️

Cluster Destruction: When you're done, simply run python3 terranetes.py cluster terminate and it gracefully destroys the cluster, cleans up resources, and even purges the Multipass instances. 💣✨

Fresh Start, Need a new deployment with new IPs from the DHCP? No problem! Run the command again, and voilà, your new Kubernetes cluster is deployed and ready to go. Each new deployment gets fresh IPs dynamically assigned from the DHCP, ensuring no conflicts and a seamless experience. 🌐

This approach combines the best of both worlds: the flexibility and reliability of Kubespray with the lightweight convenience of Multipass. Whether you're setting up a home lab or experimenting with multi-node clusters for learning, this solution takes the pain out of the process—and puts the fun back in DevOps! 😎

Ready to see the magic in action? Let’s dive in! 🚀

Prerequisites

Multipass 🌐: It is essential for creating and managing lightweight virtual machines on your local machine. It’s easy to deploy and delete. Memory - 4GB, Disk - 20GB.

Python3 🐍: Python is the backbone of the automation script. Ensure you have Python3 installed.

Ansible 📦: Kubespray relies on Ansible for orchestrating Kubernetes setup across nodes.

Kubespray 🚀: Kubespray is the tool of choice for automating Kubernetes clusters.

Bash Script 📝: This script automates the commands for deploying and destroying the Kubernetes cluster using Kubespray and Multipass.

Why Multipass? 🤔

multipass

When choosing a virtualization environment for running Kubernetes nodes, there are several options available like VirtualBox, VMware, Lima, Colima, Vagrant, etc. Each has unique features, but Multipass stands out for its simplicity and efficiency in local development. Here’s why I chose Multipass for this project:
1. Lightweight and Fast ⚡
Multipass is optimized for lightweight, fast virtual machine creation and management.

Quick Deployment: Launch VMs in seconds with minimal configuration. making it ideal for quickly spinning up and tearing down virtual machines.

This efficiency is crucial for development and testing environments where time is of the essence. ⚡

Low Overhead: Multipass VMs consume fewer resources compared to traditional hypervisors like VMware or VirtualBox.

  1. Seamless Integration 🌐 Multipass is tightly integrated with Ubuntu, making it an excellent choice for running Kubernetes clusters on Ubuntu-based images.

Prebuilt Ubuntu Images: Comes with official Ubuntu LTS images, eliminating the need to download or manage custom ISOs.

Integration with Cloud-Init: Multipass supports Cloud-Init, which allows you to automate the initial configuration of your instances. This feature is particularly useful for automating tasks and ensuring consistency across deployments. 🚀

Effortless Updates: Automatically downloads and keeps images up-to-date with the latest versions.

3. Command-Line Simplicity 🛠️
Multipass is designed with developers in mind, featuring a clean and intuitive command-line interface.

Single Command Operations: Create, delete, and manage VMs with simple commands.

Scripting-Friendly: Ideal for automation workflows, making it easy to integrate with tools like Ansible and Kubespray.

4. Cross-Platform Support 🌍
Multipass is compatible with major platforms, including Linux, macOS, and Windows, ensuring flexibility and portability.

Unified Experience: Consistent CLI across all platforms.

Cross-Platform Compatibility: Multipass runs on Windows, macOS, and Linux, providing a consistent experience across different operating systems. This cross-platform compatibility is beneficial for teams working in diverse environments. 🌐

No Dependencies: Unlike Vagrant, which requires a hypervisor like VirtualBox, Multipass works out of the box with its backend.

5. Cloud-Like Experience ☁️
Multipass mimics the simplicity of provisioning instances in the cloud, bringing that experience to your local machine.

Ease of Networking: Multipass simplifies networking setup, making it easier to configure and manage network interfaces and IP addresses for your virtual machines. This ease of use is beneficial for setting up and managing Kubernetes clusters. 🌍

**Automation-Friendly: **Multipass can be easily integrated into automation scripts and CI/CD pipelines, making it a perfect fit for automated deployments and testing workflows. 🛠️

Dynamic IP Assignment: Leverages DHCP for dynamic IP allocation, making networking seamless.

Minimal Configuration: Abstracts away the complexities of VM networking and resource management.

6. Efficient Resource Usage 🖥️
Multipass is optimized for development environments and uses system resources efficiently.

Multipass is resource-efficient, meaning it uses fewer system resources compared to heavier alternatives like VMware or VirtualBox. This efficiency is crucial for running multiple virtual machines simultaneously without significant performance degradation. 💻

Customizable Resources: Allocate specific CPU, memory, and disk resources for each VM.

Low Host Impact: Uses lightweight QEMU as the backend on Linux and macOS, ensuring your host system remains performant.

compare-multipass

Why I Choose Multipass for My Project? 💡
For this project, the goal was to deploy and manage multi-node Kubernetes clusters locally with minimal effort. Multipass checked all the boxes:

Simplicity: Easy VM provisioning without dealing with hypervisor complexities.

Speed: Rapid setup and teardown of VMs.

Integration: Works seamlessly with Ubuntu and aligns perfectly with Kubespray’s requirements.

Automation: Script-friendly CLI for hands-free deployment and destruction of clusters.

Why Kubespray?

Kubespray

*When it comes to deploying Kubernetes clusters, there are numerous tools to choose from, including Kind, Minikube, k3s, MicroK8s, and kubeadm. Each has its strengths and serves specific use cases. So, why choose Kubespray for setting up a production-grade multi-node Kubernetes cluster? Let’s explore! *🚀

  1. Production-Grade Setup 🌟 Kubespray is designed to create highly available, production-ready Kubernetes clusters.

Supports Multi-Node Clusters: While tools like Minikube and Kind are excellent for single-node or small-scale environments, Kubespray shines in setting up robust multi-node configurations.

Built-In HA: Out-of-the-box high availability (HA) ensures resilience, making it ideal for production workloads.

With Kubespray, you can easily scale your clusters by adding or removing nodes as needed. This flexibility makes it a preferred choice for dynamic environments.

2. Highly Customizable 🎨
Kubespray provides the flexibility to customize every aspect of the cluster.

Fine-Tuned Configuration: Modify parameters like container runtime, network plugins, and cloud providers.

Advanced Options: Includes additional features like network policies, cluster monitoring, and logging by default.

Support for Various CNIs: Choose from Calico, Cilium, Flannel, and more based on your networking needs.

Kubespray offers extensive configuration options, allowing you to tailor your Kubernetes setup to specific requirements. This level of customization is often not available in simpler tools like MicroK8s.

3. Idempotent and Reliable 🔁
Kubespray leverages Ansible for orchestration, ensuring idempotency and reliability.

Ansible Integration: Kubespray leverages Ansible for configuration management, providing a powerful and flexible way to automate complex tasks. This integration enhances the overall automation and management capabilities.

Error Recovery: If an operation fails, rerunning the playbook picks up where it left off without breaking the cluster.

Scalability: Easily scale your cluster by adding or removing nodes.

4. Cross-Platform Support 🌍
Unlike other tools that are tied to specific environments, Kubespray works seamlessly across various platforms.

Cloud Provider Agnostic: Kubespray can deploy clusters across various cloud providers and on-premises environments, providing versatility that other tools might lack.

On-Premise and Cloud: Supports deployment on on-premise bare metal, cloud VMs, or a hybrid setup.

Multi-Provider Flexibility: Compatible with AWS, GCP, Azure, OpenStack, and more.

5. Kubernetes Compliance ✅
Kubespray adheres to upstream Kubernetes standards, ensuring compatibility with the latest versions.

Community and Support: Kubespray has a strong and active community, offering plenty of resources, documentation, and support for troubleshooting and optimization.

Security Features: Kubespray includes built-in security features and best practices, ensuring your clusters are secure from the start. 🔒

No Vendor Lock-In: Fully compliant with the Kubernetes API, so you’re not locked into proprietary solutions.

Community-Driven: Supported by the Kubernetes SIG (Special Interest Group), ensuring regular updates and robust community support.

compare-kubespray

Why I Chose Kubespray for My Project? 💡
For this project, the goal was to automate the deployment of production-grade, highly available, multi-node Kubernetes clusters in a local environment and also customisable.

Kubespray provided the perfect balance between flexibility, reliability, and ease of automation.

Combining it with Multipass made the process lightweight and repeatable with minimal resource overhead.

Why My TerraNetes Over Kubespray? 🚀

terranetes

While Kubespray is a fantastic tool for deploying production-grade Kubernetes clusters, it requires significant setup and configuration. TerraNetes, on the other hand, simplifies the entire process by automating everything with just one command. Here's a detailed comparison and why TerraNetes stands out:

1. Node Provisioning Made Simple 🛠️
Kubespray: Requires manual provisioning of nodes before you can deploy Kubernetes.

You need to set up virtual machines or physical servers, configure SSH access, and ensure the nodes meet Kubernetes prerequisites.

Customization can be time-consuming and prone to errors.

TerraNetes: Handles node provisioning out of the box.

Automatically spins up and configures virtual machines using Multipass.

No manual intervention is required to create or manage nodes.

2. Out-of-the-Box Configuration 🎁
**Kubespray: **Requires detailed configuration for nodes, including:

Firewall Rules: Ensure necessary ports are open for Kubernetes components.

Hostnames: Set unique and resolvable hostnames for all nodes.

Swap Off: Manually disable swap to ensure Kubernetes’s stability.

Kernel Modules: Enable necessary modules like br_netfilter with modprobe.

TerraNetes: Takes care of all these configurations automatically.

Ensures all nodes are pre-configured with the required settings.

No need to worry about forgetting a crucial step in node setup.

3. Ansible Connection Simplified 🔗
Kubespray: Requires SSH access and key management to establish connections between the control node and worker nodes.

This includes creating SSH keys, distributing them to nodes, and ensuring proper permissions.
TerraNetes: Removes the need for manual SSH setup.

Automatically configures Ansible connections during the provisioning process.

New ssh-keys are being created on every deployment and deleted on every termination for security reasons.

Automatically update the ansible inventory file with new node names and node IPs.

No manual key distribution or host configuration is necessary.

4. Single Command Deployment 💻
Kubespray: Deployment involves multiple steps:

Provision nodes, prepare them, configure Ansible inventory, and run the playbooks.

Each step requires careful attention to detail to avoid errors.

TerraNetes: Simplifies deployment with one command.

Handles node creation, configuration, and Kubernetes installation in a single execution.

Saves time and ensures consistency across all environments.

5. Automation and User Experience 🎯
Kubespray: Powerful but designed for experienced users.

Suitable for advanced scenarios where deep customization is required.

However, it has a steep learning curve and requires significant effort to set up.

TerraNetes: Built with a focus on automation and ease of use.

Perfect for users who want a Kubernetes cluster up and running quickly without dealing with the underlying complexities.

Designed to minimize errors and reduce the barrier to entry for Kubernetes deployment.

6. Time-Saving Advantage ⏳
Kubespray: Can take hours or even days to configure and deploy, depending on your expertise and environment.

TerraNetes: Gets you a fully functional Kubernetes cluster in minutes, thanks to its streamlined approach.

compare-terranetes

When to Choose TerraNetes?
Rapid Prototyping: Need a cluster quickly without worrying about the underlying infrastructure.
Simplicity: Want to focus on using Kubernetes, not setting it up.
Automation: Prefer an end-to-end automated solution with minimal manual intervention.

While Kubespray shines in highly customizable and production-grade setups, TerraNetes provides an unmatched level of simplicity and speed. With just one command, it does all the heavy lifting - node provisioning, configuration, and deployment - so you can focus on building and deploying applications. 🎉

Testing the Terranetes project

Demo Video

Conclusion 🎯
The TerraNetes project redefines the Kubernetes deployment experience with it’s simplicity, automation, and efficiency. It revolutionizes the way we deploy and manage production-grade multi-node Kubernetes clusters. Automating the entire process with just a single command simplifies the complexity of node provisioning, SSH configuration, updating node hostnames, firewall setup, and more. This out-of-the-box solution saves time, reduces errors, and makes Kubernetes deployment accessible to everyone, whether you're setting up a home lab or experimenting with multi-node clusters for learning.

With Terranetes, you can focus on what truly matters—building and scaling your applications—while leaving the heavy lifting of cluster management to the automation script. The combination of Kubespray and Multipass, coupled with the streamlined approach of Terranetes, ensures a robust, scalable, and hassle-free Kubernetes experience. 🌐✨

Whether you're a DevOps professional, developer, or Kubernetes enthusiast, TerraNetes empowers you to harness the full potential of Kubernetes in the fastest and easiest way possible. 🚀

Linkedin

Top comments (0)