Juju 101 - Ready! Steady! Go! [1/12]

Overview

Duration: 3:00

Before you get started!

Welcome to the world of operators! In this series of tutorials, we will walk you through all the necessary steps to explore and learn operators through some basic examples. Starting with just your laptop, you will learn how to use operators for sophisticated application management at scale, across multiple Kubernetes clusters, cloud virtual machines, and ultimately bare metal.

This tutorial is the first in the “Phase 1 - K8s operators on your local workstation” series.

Explore other tutorials >

What are operators?

Operators are pieces of software designed to drive other software. They encapsulate the operational code of applications, shifting the burden of lifecycle management from configuration files and manual steps to an operator instance. Operators are a form of automation that is gaining popularity in the Kubernetes domain where traditional configuration management does not work. However, operators work with traditional virtual and bare metal machines as well.

Learn more about operators >

What is Juju OLM?

Juju is a universal Operator Lifecycle Manager (OLM) which provides services to operators. It provides resources for operators, deploys them, manages their lifecycle, delivers configuration updates, etc. Juju OLM is universal, meaning that it supports container substrates like Kubernetes as well as traditional machine substrates like bare metal, VMware, OpenStack, or public cloud instances.

Learn more about Juju OLM >

In this tutorial, you will learn how to:

  • Set up your development environment with a local Kubernetes cluster
  • Bootstrap Juju controller using Juju CLI
  • Deploy your first application with an operator
  • Use Juju CLI to monitor deployed applications

You will only need:

  • A machine with 8 GB of RAM

Prerequisites (short track)

Duration: 10:00

In order to set up your development environment with a local Kubernetes cluster based on MicroK8s, execute the following commands:

sudo snap install --classic microk8s
sudo usermod -a -G microk8s $USER
su - $USER
microk8s status --wait-ready
microk8s.enable dns storage
sudo snap install juju --classic --channel=2.9
juju bootstrap microk8s mk8s
juju add-model monitoring

Refer to the “Prerequisites (long track)” section for detailed information on every single step in this process. Otherwise, navigate directly to the “Deploy an application” section.

Prerequisites (long track)

Duration: 10:00

The purpose of this section is to provide a detailed description of every single step from the “Prerequisites (short track)” section. If you already executed those commands, navigate directly to the “Deploy an application” section.

Local Kubernetes cluster

We will use MicroK8s to bootstrap a local Kubernetes cluster. In order to install MicroK8s on Linux, execute the following command:

$ sudo snap install --classic microk8s

Then grant necessary permissions:

$ sudo usermod -a -G microk8s $USER
$ su - $USER

MicroK8s installation may take a few minutes. Make sure it has finished before proceeding with the next steps:

$ microk8s status --wait-ready

After a while this command should result in the following output:

As the last step, enable necessary add-ons:

$ microk8s.enable dns storage

Juju client

Before you start using Juju, you have to install the Juju client. In order to proceed with that execute the following command:

$ sudo snap install juju --classic --channel=2.9
juju (2.9/stable) 2.9.8 from Canonical✓ installed

That’s it. You can now interact with your Juju environment by using the juju command:

$ juju help
...
    upload-backup               - Store a backup archive file remotely in Juju.
    users                       - Lists Juju users allowed to connect to a controller or model.
    version                     - Print the Juju CLI client version.
    wallets                     - List wallets.
    whoami                      - Print current login details.

Bootstrap Juju controller

Before you start deploying applications on top of MicroK8s, you have to bootstrap Juju controller there. First, start by confirming whether MicroK8s is recognised by Juju as one of the available substrates:

$ juju list-clouds
Only clouds with registered credentials are shown.
There are more clouds, use --all to see them.

Clouds available on the controller:
Cloud     Regions  Default    Type
microk8s  1        localhost  k8s

Clouds available on the client:
Cloud       Regions  Default     Type       Credentials  Source    Description
...
microk8s    1        localhost   k8s        1            built-in  A Kubernetes Cluster

Once it shows up on the list, you can bootstrap Juju controller on MicroK8s by executing the following command:

$ juju bootstrap microk8s mk8s

This command takes a while, but finally, you should be able to see the following output:

$ juju bootstrap microk8s mk8s
Creating Juju controller "mk8s" on microk8s/localhost
Bootstrap to Kubernetes cluster identified as microk8s/localhost
Fetching Juju Dashboard 0.8.0
Creating k8s resources for controller "controller-mk8s"
Downloading images
Starting controller pod
Bootstrap agent now started
Contacting Juju controller at 10.152.183.68 to verify accessibility...

Bootstrap complete, controller "mk8s" is now available in namespace "controller-mk8s"

Now you can run
        juju add-model <model-name>
to create a new model to deploy k8s workloads.

You can also list all deployed controllers by executing the following command:

$ juju list-controllers
Use --refresh option with this command to see the latest information.

Controller          Model              User   Access     Cloud/Region        Models  Nodes    HA  Version
mk8s*               controller         admin  superuser  microk8s/localhost       1      1     -  2.9.9

Finally, create a model for your first application:

$ juju add-model monitoring
Added 'monitoring' model on microk8s/localhost with credential 'microk8s' for user 'admin'

And make sure it’s been successfully created:

$ juju models
Controller: mk8s

Model        Cloud/Region        Type        Status     Access  Last connection
controller   microk8s/localhost  kubernetes  available  admin   just now
monitoring*  microk8s/localhost  kubernetes  available  admin   never connected

Deploy an application

Duration: 5:00

Operators and Juju OLM provide provisioning capabilities so that resource provisioning and application deployment process is fully automated.

In the following steps, we will deploy our first application with an operator. We will use prometheus as an example. Prometheus is an open-source monitoring and alerting toolkit.

In order to deploy juju-hello with an operator, execute the following command:

$ juju deploy prometheus-k8s
Located charm "prometheus-k8s" in charm-hub, revision 1
Deploying "prometheus-k8s" from charm-hub charm "prometheus-k8s", revision 1 in channel stable

The deployment of prometheus has just started. You can monitor the progress by running the following command:

$ juju status

Once it turns “active” state you may consider the deployment to be finished:

$ juju status
Model       Controller  Cloud/Region        Version  SLA          Timestamp
monitoring  mk8s        microk8s/localhost  2.9.9    unsupported  17:30:00+01:00

App             Version                 Status  Scale  Charm           Store     Channel  Rev  OS          Address       Message
prometheus-k8s  prom/prometheus:latest  active      1  prometheus-k8s  charmhub  stable     1  kubernetes  10.152.183.7

Unit               Workload  Agent  Address     Ports     Message
prometheus-k8s/0*  active    idle   10.1.98.19  9090/TCP

Next steps

Duration: 2:00

Congratulations! You have reached the end of this tutorial.

You can now move to the next tutorial - “2. Scale” - or explore other tutorials.

In this tutorial you have learnt how to:

  • Set up your development environment with a local Kubernetes cluster
  • Bootstrap Juju controller using Juju CLI
  • Deploy your first application with an operator
  • Use Juju CLI to monitor deployed applications

Where to go from here?

  • Learn more about Juju OLM
  • Browse the Open Operator Collection store
  • Ask a question
  • Report a bug