Member-only story
Create a Self-Contained and Portable Kubernetes Cluster With K3S and Packer
A portable Kubernetes cluster for development or legacy infrastructure
In this article, we will build a virtual machine hosting a one-node Kubernetes cluster.
Let’s start with a basic question: Why would you want a Kubernetes cluster running in a VM? Well, I see two reasons.
First, it’s an easy way to provide a shared low-cost cluster as a development environment in a few seconds. You just have to boot the VM, and voila: You have a fully functional cluster. You may not want to pay your cloud provider an expensive managed control plane for this use case.
If the cluster is not shared — and for the sake of completeness — developers may run a local K3D on their laptop:
A more twisted and real motivation is enabling Kubernetes for customers who are only running traditional on-premise VMs and are not ready to commit to the technology. If you have built a product with Kubernetes in mind, you certainly don’t want to fork your deployment strategy and create a specific setup for a VM running in your customer data center or cloud provider. But by running a whole Kube cluster on a VM, you can now deploy your product made for Kubernetes with only a few minor tweaks.
Our Tools of Choice
In this walkthrough, we will use:
- Packer by HashiCorp to create our virtual machine image.
- K3S from Rancher for a performant and configurable cluster.
- VirtualBox from Oracle for the hypervisor as an example.
Writing the Packer image
Decide on the VM characteristics
The first step is to select a Linux OS of your choice. We will use Ubuntu Server as an example. You also need to decide on the capacity of this VM: its RAM, CPU, and disk size.