Run Kubernetes on a Mac with Kube Solo

14 Oct 2016

Kubernetes is one of the best known container orchestration tools, but often, setting up a dev environment with Kubernetes is a daunting task. This is especially true for people who are just getting started with containers and orchestration in general.

Fortunately, now that Docker for Mac is generally available, you can easily run both Docker and Kubernetes on OS X allowing you to quickly develop, containerize, and work with your applications as if they were in production. But what if you want to get up and running with Kubernetes on OS X?

In this post, I will show you how to set up a Kubernetes dev environment on OS X with a tool called Kube-Solo.

What Is Kube Solo

Kube Solo provides a lightweight Kubernetes environment on your local machine, needing very little setup or installation effort. With Kube Solo, you can provision a CoreOS server and bootstrap a Kubernetes development environment in just a few clicks.

Kube Solo is essentially a status bar app (with a CLI tool) wrapping corectl, a GUI for corectld. It lets you run CoreOS VMs on OS X via xhyve.

For the uninitiated, xhyve is a lightweight OS X virtualization solution that uses the OS X native hypervisor framework, eliminating the need to use Virtual Box or other similar virtualization software to run your CoreOS VMs.

In summary: Kube Solo wraps corectl. corectl wraps corectld, a server daemon that helps you run CoreOS VMs on OS X. corectld uses Docker HyperKit (which is based on xhyve) in the background as its virtualization mechanism.

Download and Installation

Before you can install Kube Solo, make sure you are running OS X 10.10.3 Yosemite or later. You also need the corectl app installed.

Let's start with the corectl app.

To install the corectl app, download the latest disk image from the releases page, mount it and copy the file to /Applications directory.

image alt text

Now, launch the app.

You should see the corectl app icon on the OS X menu bar. Just select this icon to start, stop, or update the tools needed to run CoreOS VMs on OS X.

This is what the corectl menu looks like:

image alt text

Next up is Kube Solo.

To proceed, download the latest Kube Solo release.

Then, install and launch it like you did with corectl. You should see Kube Solo app icon on the OS X menu bar.

Here's what that menu looks like:

image alt text

The installation process is finished. Let's move on.

Launch a Kubernetes Cluster

To launch a Kubernetes cluster, you'll need to first launch the corectl app and get the CoreOS VM running.

To do so, select the corectl app icon on your OS X menu bar and check whether there is a tick mark next to Server is running. This indicates that your CoreOS VM is available for Kube Solo.

If you need to update the CoreOS VM image, you can do it via corectl app. Just select Fetch latest CoreOS ISO and choose which channel to use. The image will be updated for you. Be sure to restart the app to make sure the latest image is loaded.

The next step is to launch the cluster via Kube Solo.

Select the Kube Solo menu bar icon, then select Up. This will launch a command prompt to display the progress. If everything goes well, you'll see a k8solo-01 node with a Ready status. To confirm, execute the command kubectl cluster-info.

You should get a response like this:

image alt text

After a successful install, you can also control Kube Solo via the ksolo CLI tool.

The ksolo tool resides in the ~/kube-solo/bin and ~/bin directories. You can use ksolo with a few simple commands: start, stop, status, ip, ssh, and shell. For example ksolo status.

If you plan on using ksolo regularly, be sure to add the correct directory to your $PATH.

Your Kubernetes cluster is now up and running. We can move on.

Run a Docker Container on Your Kubernetes Cluster

Each container in a Kubernetes pod has its own image, and currently, the only types of image supported by Kubernetes are Docker images.

To run your own Docker image on Kubernetes, you either need to use a local image and refer to it in a Kubernetes pod directly, or push your Docker images to a container registry and refer to them from a Kubernetes pod.

For the uninitiated, a registry is a cloud-based Docker image repository that works with many popular continuous delivery systems. Almost all the major cloud companies offer container registries: Google Container Registry, Docker Hub, Amazon EC2 Container Registry, GitLab Container Registry, and more.

These registries provides authentication, work group structure, workflow tools like webhooks and build triggers, and privacy tools like private repositories for storing images you don't want to share publicly. In addition, uploading an image to a registry lets you share your work with others.

So, how do you build Docker images? If you're a seasoned container dev you probably already know how to do this, but for beginners, I previously wrote a brief intro showing you how to create a Docker image with a Dockerfile from scratch.

Note: Kube Sole includes a Docker CLI tool in the ~/bin directory that interfaces with the CoreOS VM's Docker API, and you can use this to build images!

To run your container image on Kubernetes, switch to the iTerm window that pops up automatically when you launch your Kubernetes cluster.

If you're working with local images, you then need to change to the directory where you have your Dockerfiles.

Now, use the kubectl run command to launch your pods.

Here is how that looks:

$ kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster"

The kubectl run command creates a deployment named nginx on your Kubernetes cluster. You should get a response like this:

deployment "nginx-app" created

A deployment (in Kubernetes terms) is a logical object that lets you manage and even automate things like replicas and updates to your application in a simple, declarative way. For example, now that you have a nginx deployment, let's say you'd like to use nginx v1.10.1 on all your pods. You can do this by editing the current deployment, like so:

$ kubectl edit deployment/nginx-deployment

From there, you can change .spec.template.spec.containers[0].image to nginx: 1.10.1.

There are several other interesting deployment use cases. Read about them in the official docs.

Now we have a deployment set up, we can expose a new service like so:

$ kubectl expose deployment nginx-app --port=80 --name=nginx-http

You should get a response like:

service "nginx-app" exposed

A service is a logical abstraction of the pods and the policies they adhere to. Pods are dynamic in nature and can be replaced, but a service represents the functional aspect that the pods provide. So, no matter which pods provides the functionality, a service remains up and running.

Above, we created a service based on the nginx-app deployment. This means Kubernetes will make sure the nginx-app service is available even if the underlying pods change.

Check the official docs for more about services or the kubectl tool.

Wrap Up

Setting up a local development environment with Docker and Kubernetes on OS X doesn't have to be a pain. With Kube-Solo and corectl, you can get things up and running in a snap. And thanks to advances in corectl, we can do all of this in a way that makes use of the OS X native hypervisor framework.

Posted in Kubernetes, OS X, Kube Solo

triangle square circle

Did you enjoy this post?