Deploying Secure Firecracker MicroVMs on K8s using Weave FireKube

Introduction

At their 2018 annual Re:Invent conference, AWS announced an exciting new product called "Firecracker" that is quickly setting the cloud-native ecosystem on fire. Firecracker is a Virtual Machine Manager (VMM) exclusively designed for running transient and short-lived processes. In other words, it is optimized for running functions and serverless workloads that require faster cold start and higher density.

Using the same technology that Amazon uses for AWS Lambda and AWS Fargate, Firecracker delivers the speed of containers with the security of VMs and has the potential to disrupt the current container and serverless technologies.

What is Weave Ignite?

While Firecracker has a ton of potential, it's still in its early stages so getting it up and running can be a bit tedious. The goal of Ignite is to solve this issue by adopting its developer experience from containers.

With Ignite, you just pick a container image that you want to run as a VM and then execute ignite run instead of docker run.

There’s no need to use VM-specific tools to build .vdi, .vmdk, or .qcow2 images, just do a docker build from any base image you want (e.g. ubuntu:18.04 from Docker Hub), and add your preferred content.

You can even use Buildpacks! As seen in my other blog post here. In this case, you would just follow the same steps, except you would build the image via the pack command.

What is Firekube?

Firekube is a new open-source Kubernetes distribution that enables the use of Weave Ignite and GitOps to enable the setup of secure VM clusters. Firekube pulls everything from Git, detects your operating system and can boot up a secure cluster of VMs from nothing in 2.5 minutes.

A Firekube cluster has the following properties:

  1. Runs Kubernetes (now K8s, possibly K3s in future)
  2. High-grade VM security via the Firecracker KVM isolation
  3. Fast start-up and tear down of VMs e.g. for functions and serverless apps
  4. Scales from zero to production - uses standard k8s plugins for networking, etc
  5. “Lift and shift” software into VMs
  6. Run containers inside VMs or alongside VMs on the same CNI network

Creating a Firekube Cluster

Firekube is a Kubernetes cluster working on top of Ignite and Firecracker. Firekube clusters are operated with GitOps.

Ignite and Firecracker only works on Linux as they need KVM. However, it will also work on macOS using footloose: the Kubernetes nodes are then running inside containers.

Prerequisites: Docker, Git, kubectl 1.14+.

  1. Fork this repository.
  2. Clone your fork and cd into it. Use the SSH git URL as the script will push an initial commit to your fork:
Shell
 




x


 
1
export user="" # Your GitHub handle or org
2
 
          
3
git clone git@github.com:$user/wks-quickstart-firekube.git
4
cd wks-quickstart-firekube


3. Start the cluster: 

Shell
 




xxxxxxxxxx
1


 
1
./setup.sh


This step will take several minutes.

Export the KUBECONFIG environment variable as indicated at the end of the installation:

Shell
 




xxxxxxxxxx
1


 
1
export KUBECONFIG=/home/damien/.wks/weavek8sops/example/kubeconfig


Enjoy your Kubernetes cluster! 

Shell
 




xxxxxxxxxx
1


 
1
$ kubectl get nodes
2
NAME               STATUS   ROLES    AGE     VERSION
3
67bb6c4812b19ce4   Ready    master   3m42s   v1.14.1
4
a5cf619fa058882d   Ready    <none>   75s     v1.14.1



Watch GitOps in Action

Now that we have a cluster installed, we can commit Kubernetes objects to the git repository and have them appear in the cluster. Let's add podinfo, an example Go microservice, to the cluster.

Shell
 




xxxxxxxxxx
1


 
1
kubectl apply --dry-run -k github.com/stefanprodan/podinfo//kustomize -o yaml > podinfo.yaml
2
git add podinfo.yaml
3
git commit -a -m 'Add podinfo Deployment'
4
git push


A few seconds later, you should witness the apparition of a podinfo pod in the cluster: 

Shell
 




xxxxxxxxxx
1


1
$ kubectl get pods
2
NAME                       READY   STATUS    RESTARTS   AGE
3
podinfo-677768c755-z76xk   1/1     Running   0          30s


To view podinfo web UI:

  1. Expose podinfo locally:
Shell
 




xxxxxxxxxx
1


 
1
kubectl port-forward deploy/podinfo 9898:9898


2. Point your browser to http://127.0.0.1:9898


Deleting a Firekube cluster

Run:

Shell
 




xxxxxxxxxx
1


 
1
./cleanup.sh



Using a Private Git Repository with Firekube

To use a private git repository instead of a fork of wks-quickstart-firekube:

  1. Create a private repository and push the wks-quickstart-firekube master branch there. Use the SSH git URL when cloning the private repository:
Shell
 




xxxxxxxxxx
1


 
1
git clone git@github.com:$user/$repository.git
2
cd $repository
3
git remote add quickstart git@github.com:weaveworks/wks-quickstart-firekube.git
4
git fetch quickstart
5
git merge quickstart/master
6
git push


2. Create an SSH key pair: 

Shell
 




xxxxxxxxxx
1


 
1
ssh-keygen -t rsa -b 4096 -C "damien+firekube@weave.works" -f deploy-firekube  -N ""


3. Upload the deploy key to your private repository (with read/write access): 


4. Start the cluster:

Shell
 




xxxxxxxxxx
1


1
./setup.sh --git-deploy-key  ./deploy-firekube



Final Thoughts

You've now learned the basic steps it requires to provision a Kubernetes cluster based on Firecracker VM's with Firekube. You should explore a bit of the different options the platform provides such as using Ignite to spin up MicroVM's with Buildpack instead of Docker. I hope you liked this post, and I plan to dive into this a bit more in the future. Thanks for reading!

 

 

 

 

Top