Juju 101 - Teardown [7/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 assumes you have successfully completed the previous tutorial - “6. Updates”.

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:

  • Remove an application unit with an operator

  • Remove an application with all its units and relations

  • Remove all deployed applications with their units and relations

  • Remove Juju controller that was previously bootstrapped

You will only need:

  • A machine with 8 GB of RAM

  • Microk8s and Juju installed

  • Juju controller bootstrapped on MicroK8s

  • The Prometheus and Grafana operators deployed to Microk8s

Remove an application unit

Duration: 5:00

Operators and Juju OLM provide lifecycle management capabilities so that applications can be torn down in a fully automated way.

In the following steps, we will remove one of the deployed application units, the application itself, and finally, the entire Juju model. We will also outline how to remove the Juju controller.

First, let’s see what the current status of the model is:

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

App             Version                  Status  Scale  Charm           Store     Channel  Rev  OS          Address         Message
grafana-k8s     grafana/grafana@7f26ece  active      1  grafana-k8s     local                0  kubernetes  10.152.183.126
prometheus-k8s  prom/prometheus:latest   active      2  prometheus-k8s  charmhub  stable     1  kubernetes  10.152.183.7

Unit               Workload  Agent  Address     Ports     Message
grafana-k8s/0*     active    idle   10.1.98.62  3000/TCP
prometheus-k8s/0*  active    idle   10.1.98.51  9090/TCP
prometheus-k8s/1   active    idle   10.1.98.5   9090/TCP

As we can see, there are two units of the Prometheus application. We can remove one of the units by executing the following command:

$ juju remove-unit prometheus-k8s --num-units=1
scaling down to 1 units

and watch the changes by running the juju status command in the “watch” loop:

$ watch --color 'juju status --color'
Model       Controller  Cloud/Region        Version  SLA          Timestamp
monitoring  mk8s        microk8s/localhost  2.9.9    unsupported  14:30:03+01:00

App             Version                  Status   Scale  Charm           Store     Channel  Rev  OS          Address         Message
grafana-k8s     grafana/grafana@7f26ece  active       1  grafana-k8s     local                0  kubernetes  10.152.183.126
prometheus-k8s  prom/prometheus:latest   waiting      1  prometheus-k8s  charmhub  stable     1  kubernetes  10.152.183.7

Unit               Workload    Agent      Address     Ports     Message
grafana-k8s/0*     active      executing  10.1.98.17  3000/TCP
prometheus-k8s/0*  active      idle       10.1.98.51  9090/TCP
prometheus-k8s/1   terminated  executing  10.1.98.4   9090/TCP  unit stopped by the cloud

Relation provider           Requirer                       Interface           Type     Message
grafana-k8s:grafana         grafana-k8s:grafana            grafana-peers       peer
grafana-k8s:grafana-source  prometheus-k8s:grafana-source  grafana-datasource  regular

After a while the “prometheus/1” unit should be removed, resulting in the following output:

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

App             Version                  Status  Scale  Charm           Store     Channel  Rev  OS          Address         Message
grafana-k8s     grafana/grafana@7f26ece  active      1  grafana-k8s     local                0  kubernetes  10.152.183.126
prometheus-k8s  prom/prometheus:latest   active      1  prometheus-k8s  charmhub  stable     1  kubernetes  10.152.183.7

Unit               Workload  Agent  Address     Ports     Message
grafana-k8s/0*     active    idle   10.1.98.17  3000/TCP
prometheus-k8s/0*  active    idle   10.1.98.51  9090/TCP

Relation provider           Requirer                       Interface           Type     Message
grafana-k8s:grafana         grafana-k8s:grafana            grafana-peers       peer
grafana-k8s:grafana-source  prometheus-k8s:grafana-source  grafana-datasource  regular

Remove an application

Duration: 5:00

In a similar way, we can remove the entire Prometheus application. When removing an application, Juju will clean up all relations setup by that application and remove all units containing that application.

In order to completely remove Prometheus, execute the following command:

$ juju remove-application prometheus-k8s
removing application prometheus-k8s
- will detach storage database/0

Again, we can watch the changes by running the “watch” loop with the juju status command:

$ watch --color 'juju status --color'

After a period of time, Prometheus is fully removed from our deployment:

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

App          Version                  Status  Scale  Charm        Store  Channel  Rev  OS          Address         Message
grafana-k8s  grafana/grafana@7f26ece  active      1  grafana-k8s  local             0  kubernetes  10.152.183.126

Unit            Workload  Agent  Address     Ports     Message
grafana-k8s/0*  active    idle   10.1.98.56  3000/TCP

Relation provider    Requirer             Interface      Type  Message
grafana-k8s:grafana  grafana-k8s:grafana  grafana-peers  peer

Remove the model

Duration: 5:00

In order to remove all deployed applications with their units and relations, we can use juju destroy-model command. We will cover Juju models in detail in the next tutorial, but as of now, simply execute the following command, which is an interactive prompt, so enter y to continue as there is no way to recover after this has been done:

$ juju destroy-model monitoring --release-storage
WARNING! This command will destroy the "monitoring" model.
This includes all containers, applications, data and other resources.

Continue [y/N]? y
Destroying model
Waiting for model to be removed, 1 application(s), 5 volume(s), 5 filesystems(s)...
Waiting for model to be removed, 1 application(s), 1 volume(s), 1 filesystems(s)....
Waiting for model to be removed, 1 application(s)......
Waiting for model to be removed...
Model destroyed.

The “monitoring” is the name of the current model that we created in previous tutorials. We can see that all deployed applications with their units and relations are being removed. Finally, the model itself is removed too:

$ juju models
Controller: mk8s

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

We can also verify that all containers have been cleaned up by running the “kubectl: command:

$ microk8s.kubectl get pods -n monitoring
No resources found in monitoring namespace.

Remove the controller

Duration: 3:00

In some situations, you may want to remove the entire Juju controller. That will result in removing all models created under this controller, all applications, applications units, and their relations.

NOTE: The following instructions are provided for informational purposes only. The next tutorials assume you have Juju controller bootstrapped. In case you accidentally remove it, refer to the following tutorial - 1. Ready! Steady! Go! - for exact instructions on how to bootstrap a Juju controller.

In order to remove Juju controller, execute the following command:

$ juju destroy-controller --destroy-all-models --release-storage mk8s
WARNING! This command will destroy the "mk8s" controller.
This includes all machines, applications, data and other resources.

Continue? (y/N):y
Destroying controller
Waiting for hosted model resources to be reclaimed
All hosted models reclaimed, cleaning up controller machines

The “mk8s” is the name of the controller that we bootstrapped in previous tutorials. Once the command stops executing, the controller is removed:

$ juju controllers

Next steps

Duration: 2:00

Congratulations! You have reached the end of this tutorial.

You can now move to the next tutorial - “8. Models”

In this tutorial you have learnt how to:

  • Remove an application unit with an operator

  • Remove an application with all its units and relations

  • Remove all deployed applications with their units and relations

  • Remove Juju controller that was previously bootstrapped

Where to go from here?