Note: This doc has been deprecated. Please see instead: Get started with Juju.
Kubernetes – also known as K8s – provides a flexible architecture for Cloud Native applications at scale. The Juju Charmed OLM manages multi-container workloads on K8s. This guide takes you through the registration steps necessary to connect the two systems.
You don’t need to have previous knowledge of Juju or Charmed Operators to follow this guide.
Create the test environment
MS Windows and macOS users. Optional step for Ubuntu users.
- Install the Juju CLI client
- Gain access to a Kubernetes cluster
- Register the cluster with Juju
- Bootstrap a Juju controller into the cluster
- Add a model
- Deploy applications
- Relate applications
- Test your deployment
- Destroy your test environment
- Next steps
The instructions in this tutorial are based on an Ubuntu system. This section details how to quickly create a test environment on MS Windows and macOS using a virtual machine deployed by Multipass.
This section is also useful for those that are already running Ubuntu, but would like to create an isolated test environment that could be easily removed.
Info: Multipass is a tool for quickly running virtual machines from any host operating system. This will allow you to create a fully-isolated test environment that won’t impact your host system.
You can find system specific information on how to install Multipass at multipass.run.
To start a virtual machine called, for example, “microcloud”, that has 8 GB RAM allocated to it, execute:
multipass launch -n microcloud -m 8g -c 2 -d 20G
Multipass will confirm the creation:
multipass has downloaded the latest Long Term Support version of the Ubuntu operating system, you will be able to enter a command-line with the
multipass shell microcloud
This gives you access to the shell (you may see a different prompt, depending on the version installed):
You are now ready to follow the rest of this guide in our newly created Ubuntu machine. All commands should be typed in this shell.
If for whatever reason you need to interrupt this tutorial,we recommend running
multipass stop microcloud to stop the instance. When you resume, run
multipass start microcloud.
We will now install the Juju client via
snap: this is the easiest and fastest way to get started with Juju.
Other installation methods You can find a comprehensive list of all the ways you have to install Juju at Juju | How to install `juju` .
The following command will install the Juju client:
sudo snap install juju --classic
If the installation was successful, you will see a message similar to the one below:
juju 2.8.10 from Canonical✓ installed
Juju supports a variety of Kubernetes distributions running on your laptop, private infrastructure, or public cloud. In this tutorial we will use MicroK8s. To install MicroK8s, execute:
sudo snap install microk8s --classic --channel=1.24
You don’t need to register MicroK8s explicitly—Juju can retrieve the configuration file for the cluster automatically.
If for any reason that can’t be done automatically, you can manually point Juju to the cluster’s configuration file.
Copy the cluster’s configuration file from the master node to your local machine and save it as
$HOME/.kube/config, then run
text juju add-k8s <k8s-name>
However, there is an extra step before Juju can communicate with your MicroK8s cluster, namely, you have to enable the MicroK8s
dns addons, as shown below:
microk8s enable hostpath-storage dns
Done. Time to verify that Juju has really recognized this cluster. To check that, run:
If everything has gone OK, this should output:
Cloud Regions Default Type Credentials Source Description microk8s 1 localhost k8s 0 built-in A Kubernetes Cluster
As you can see, you now have a MicroK8s cluster which has been named, by default,
Note the mixed terminology “cluster”—“cloud”. There is a subtle difference between these concepts. However, for all intents and purposes, you now have both a MicroK8s cluster and a
To give Juju control over your cluster, let’s bootstrap a Juju controller into it, calling it
juju bootstrap microk8s overlord
The command above assumes that the config file is located at
$HOME/.kube/config (or it has been loaded manually) and you can communicate to your cluster via
To check that you have configured
kubectl correctly, execute the command:
microk8s kubectl get nodes
The next step is to create a workspace on your cluster. We do this by creating a model, as shown below. We will name ours
juju add-model tutorial-model
In the Kubernetes context, models are namespaces.
The fundamental purpose of Juju is to deploy and manage software applications in a way that is easy and repeatable. All this is done with the help of charmed operators, or ‘charms’, which are bits of code that contain all the necessary intelligence to do these things. Charmed operators can exist online in the official charm repository, Charmhub or on your local filesystem (previously downloaded from the store or written locally).
As an example, we will deploy Mattermost, an open-source, self-hostable online chat service using PostgreSQL as its database. In both cases, we will deploy them from Charmhub, which is the default source for Juju.
To deploy Mattermost, execute:
juju deploy mattermost-k8s
When deployed, this outputs:
Located charm "mattermost-k8s" in charm-store, revision 20 Deploying "mattermost-k8s" from charm-store charm "mattermost-k8s", revision 20 in channel stable
You can observe the deployment status with the following command:
watch -c juju status --format short --color
Then, to deploy PostgreSQL, run:
juju deploy postgresql-k8s
When deployed, this outputs:
Located charm "postgresql-k8s" in charm-store, revision 9 Deploying "postgresql" from charm-store charm "postgresql-k8s", revision 9 in channel stable
That’s it. Your applications are now deployed.
At this point, both applications are deployed in the model located in the Kubernetes cluster, but they don’t know about each other, although it is easy to see that one could really use the other—Mattermost needs a database and PostgreSQL can satisfy this need.
In Juju, integrating applications is a first class operation. To connect Mattermost to PostgreSQL, simply execute:
juju relate mattermost-k8s postgresql-k8s:db
Ambiguous relations. If the charmed operators in question are versatile enough, Juju may need to be supplied with more information as to how the charmed operators should be joined. In this example, we had to specify to which postresql endpoint we wanted to connect: postgresql:db That’s because postgresql has multiple endpoints for syslog, db and db_admin.
Again, watch the deployment status with the following command until both charmed operators’ status is
watch -c juju status --format short --color
Once the applications are related, this will return the following:
- mattermost/0: (agent:idle, workload:active) 8065/TCP - postgresql/0: (agent:idle, workload:active) 5432/TCP
To access the application locally, execute:
microk8s kubectl get pods -n tutorial-model
From the output, retrieve the name of the Mattermost pod.
Now use it to do port-forwarding to your local machine:
microk8s kubectl port-forward -n tutorial-model <Mattermost pod name> 8065
Now, open your browser and access the page http://localhost:8065. You should see the Mattermost home page.
Congratulations, you just deployed and integrated cloud-native applications in a Kubernetes cluster!
Once you are done, you can run
multipass delete --purge microcloud to delete your instance. You can also uninstall Multipass to remove any trace of this guide.
This tutorial has introduced you to the basic things you can do with Juju. Visit the Juju How-to docs to experiment with further features such as scaling or cross-model relations; the Juju Reference docs to learn more about the primitive notions and commands that make Juju work; or the Juju Explanation docs, just for fun.