I recently joined VMware, and one of my goals is to take a more active role in the Kubernetes (K8s) community. This goal has led me to Cluster API, a project that introduces K8s orchestration with the use of declarative style API akin to the Kubernetes API. The cloud agnostic nature of Cluster API makes it an appealing solution for projects based on just about any cloud foundation.
This post aims to shorten your time to endorphins in part by curating the Cluster API documentation. I found The Cluster API Book to contain a lot of great information (and I advise that you take a look at it), but this is me taking you straight to setting up your Cluster API environment. Below are steps that detail how to set up a local K8s cluster for Cluster API development on a laptop or desktop. For this, my machine is macOS Catalina, 8 core intel i9, 32 gb, and 1 TB. But before you proceed, I strongly encourage you to check out this article on the risks associated with the Linux utility Sudo.
1. Install Ubuntu Multipass and Create Ubuntu VM
Multipass is an Ubuntu VM orchestrator for creating “mini-clouds.” Other hypervisors like Virtualbox can also be used but for my use case, creating and managing Ubuntu VMs, I prefer the usability of Multipass.
Install Multipass by going to the ubuntu website and follow the install instructions. Once you’re done with the installation, Multipass has various Ubuntu images available.
- Find the available images
~ % multipass find
- Launch an Ubuntu 18.04 instance
~ % multipass launch -c 2 -d 32G -m 8G 18.04
This builds an Ubuntu VM with 2 CPUs, 32 gigs of storage and 8 gigs of memory.
- Display VMs
~ % multipass list
- Access the vm
~ % multipass shell <name of vm>
2. Install Golang, Kubectl, Kind and Docker on the Ubuntu VM
Once logged into the VM install the packages from the links below:
Golang install instructions – https://golang.org/doc/install
Kubectl install instructions – https://kubernetes.io/docs/tasks/tools/install-kubectl/
Kind Install instructions – https://kind.sigs.k8s.io/docs/user/quick-start
Docker install instructions – https://docs.docker.com/engine/install/ubuntu/
Configure docker for linux – https://docs.docker.com/engine/install/linux-postinstall/
3. Create K8s/Kind cluster
The cluster API Book (https://cluster-api.sigs.k8s.io/user/quick-start.html#usage) provides the instructions below on how to create a management cluster and install cClusterctl.
- Create Kind config file
$ cat > kind-cluster-with-extramounts.yaml <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
– role: control-plane
extraMounts:
– hostPath: /var/run/docker.sock
containerPath: /var/run/docker.sock
EOF
- Create Kind cluster
$ sudo kind create cluster –config kind-cluster-with-extramounts.yaml
- Install cClusterctl (the Cluster API command line tool)
$ curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.3.12/clusterctl-linux-amd64 -o clusterctl
$ chmod +x ./clusterctl
$ sudo mv ./clusterctl /usr/local/bin/clusterctl
$ clusterctl version
- Initialize the management cluster
$ sudo clusterctl init –infrastructure docker
4. Configure Google Cloud Registry, install Kustomize and Kubebuilder
The Cluster API developer section (https://cluster-api.sigs.k8s.io/developer/guide.html) outlines the instructions below:
Follow the Google Cloud Registry steps and use the local shell setup on the VM – https://cloud.google.com/container-registry/docs/quickstart
Optionally, a different registry can be used to manage images. More on this in the Cluster API book.
- Install Kustomize (used for customizing YAML files) – https://kubectl.docs.kubernetes.io/installation/kustomize/binaries/
$ curl -s “https://raw.githubusercontent.com/\
kubernetes-sigs/kustomize/master/hack/install_kustomize.sh” | bash
$ sudo mv kustomize /usr/local/bin/
$ kustomize version
Kubebuilder install instructions – https://book.kubebuilder.io/quick-start.html#installation
- Get envsubst – https://github.com/drone/envsubst
$ go get -v github.com/drone/envsubst
5. Deploy Cert-Manager and install Tilt
Don’t just deploy Cert-Manager as suggested here: https://cluster-api.sigs.k8s.io/developer/guide.html#cert-manager
Start by checking (verify the installation) if Cert-Manager is installed as shown here: https://docs.cert-manager.io/en/release-0.11/getting-started/install/kubernetes.html#
If certificates get created then skip this step. If not, then install cert-manager using regular manifests.
Tilt installation – https://docs.tilt.dev/install.html#linux
- Install Homebrew – https://brew.sh/
$ /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
$ sudo apt-get install build-essential
$ brew install gcc
- Install ctlptl – https://github.com/tilt-dev/ctlptl
- Install Tilt
$ curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
Clone Cluster API repo and create a tilt-settings.json file – https://cluster-api.sigs.k8s.io/developer/tilt.html#create-a-tilt-settingsjson-file
- Start Tilt
$ tilt up
6. Set up X display for Tilt GUI
Install Firefox, xorg and openbox on the Ubuntu VM
Install XQuartz on your Mac
SSH with -X option from your Mac to the Ubuntu VM and run Firefox
The Tilt GUI will be at ‘http://localhost:10350/’ when you choose the Tilt browser option
Conclusion
While there has been an article that outlined the steps to set up Cluster API on a Virtualbox VM for development, I made the decision to go with Multipass for its ease of use. I also cover two additional features from The Cluster API Book, Cert-Manager and Tilt. And finally, I show how to get to the Tilt GUI. In a nutshell, my setup shows an easy way to create a Kubernetes Cluster API development environment with Tilt, on an easy to manage virtual machine. So far, I’ve found the Cluster API community to be active, responsive and welcoming. You can join the Slack interactions at #cluster-api, and the special interest group is SIG Cluster Lifecycle. I look forward to sharing more on Kubernetes and Cluster API in the future.