Deploying Kubernetes



This is a step by step guide which will demonstrate deploying a Kubernetes cluster using Juju and running a scalable web application on top. Here, we’ll be using the built in Microbot application in place of a real web application.


You will need juju and kubectl to follow along. On Linux, these can be installed with Snap (these will need to be run with sudo if you’ve not registered Snap):

snap install juju --classic
snap install kubectl --classic

On MacOS, these can be installed with Homebrew:

brew install juju
brew install kubectl

Deploying Kubernetes using Juju

First off, we need a Kubernetes cluster. To achive this, we’re going to use Juju. Juju will provision some cloud instances, install a Kubernetes cluster and then allow us to perform actions on that cluster; such as scaling out.

Juju is cloud agnostic and can even deploy onto bare metal using MaaS. In this case, we will use JaaS (Juju as a service) which will give us a friendly GUI to get started. Head over to and create an account, if you haven’t done so already.

Once you have an account, head over to and search for kubernetes in the top right search bar. In the list of results, you should see The Canonical Distribution Of Kubernetes. This has been created, by Canonical, to be production ready. Click Add to model, in the top right, to add the bundle to your model. Here you’ll see the individual parts, called charms, and their relationships.

Now you’re ready to deploy this somewhere. Click Deploy changes. The following page will allow you to name your model and select a public cloud to deploy to. In this instance, we’ll use AWS but JaaS also allows you to use Microsoft’s Azure and Google’s Cloud Platform. Once a cloud is selected, you are given a breakdown on how many instances are needed to deploy the Kubernetes cluster. You’ll then see the charms turn orange until they’re ready. If you’re interested in watching the deployment, you can open your cloud provider’s dashboard and watch the instances come up.

Accessing the Kubernetes cluster

After a few minutes, we’ll have our Kubernetes cluster. At this point we need to register our local Juju client with JaaS. This will allow us to pull the Kubernetes config file, from the cluster, to use with kubectl. To do this, run the following command:

juju register

This will launch a browser tab where you will need to enter your login details for JaaS. Once you’ve logged in, you can close the tab and test that the registration has worked with:

juju status

We should see a list of all the Apps, Units, Machines and Relations. If you’re having issues with the registration, see for help.

If you’ve not already got one, create a .kube directory in your home:

mkdir ~/.kube

And then get the config file from the Kubernetes master, using Juju.

juju scp kubernetes-master/0:config ~/.kube/config

When this file has copied, we can switch to using kubectl:

kubectl cluster-info

If all is well, you’ll be given a list of URLs where you can access various dashboards. By default, these are open and can be stopped with:

juju config kubernetes-master enable-dashboard-addons=false

If you are prompted for a login when trying to access the dashboard, you can view these with:

kubectl config view

Running the application

To keep this guide a reasonable length, we’re going to deploy a build in web application in place of something like Django or Rails.

Run the following Juju command to start the application:

juju run-action kubernetes-worker/0 microbot replicas=10

Once queued, Juju will give you a GUID. After a few seconds, copy this and suffix it to:

juju show-action-output

This will print an URL that you can copy and paste into your browser to see the different pod IDs when refreshed.

Scaling the cluster using Jaas

Later on, we may decide that we need some more Kubernets workers to handle our mighty web app. This is very simple using Jaas. Look back at your model in JaaS and look to the left. Here you can click on kubernetes-worker, followed by Units. This menu will show you the current number of running workers (3 by default). To add more, click Select all units and type how many additional units you want to add. You’ll then be shown a summary of what will change, confirm by clicking Commit changes in the bottom right and then Deploy.

Just like when we deployed, the charm will go orange whilst the changes are implemented. Because we’ve linked this model to Juju on our local machine, we can also follow along with:

juju status

Or, to watch live:

watch -cd -n1 juju status --color

Once these have deployed, you’ll be able to see them on the Nodes tab, on the Kubernetes dashboard.

The same can be done for any of the charms. For example, the Kubernetes master.

Okay, I’m done!

To avoid a big bill from your cloud provider, I suggest you tear it all down once you’re done. Using JaaS, click on your username in the top left. Here you’ll see your model underneath Models, click on the row with your model name. A button marked Destroy model will appear. Hit it, followed by Destroy!

It’s worth double checking all the instances have been destroyed in your cloud provider.


Many thanks for sticking with me through this, I hope it was somewhat useful. Please feel free to leave questions or comments below.

comments powered by Disqus