Juju 101 - Code structure [12/12]


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 - 11. Debugging.

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:

  • Find the operations code inside of the operator

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

Operator code structure

Duration: 10:00

The Python Operator Framework provides …

In the following steps, we will dig into the code structure of the XYZ operator and see how the Python Operator Framework is used to define an operations code for the application.

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.10   unsupported  10:18:09+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

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

We can use juju ssh command to SSH to the application container:

$ juju ssh prometheus-k8s/0

The file we have seen being executed in the previous tutorial was /var/lib/juju/agents/unit-prometheus-k8s-0/charm/src/charm.py. Let’s display the output of this file:

$ cat agents/unit-prometheus-k8s-0/charm/src/charm.py

def _on_config_changed(self, _):
"""Set a new Juju pod specification


We can see that on line 43 that there is a method responsible for the “config-changed” hook that was caught by pdb in the previous tutorial, calling the “self._configure_pod()” method.

Next steps

Duration: 2:00

Congratulations! You have reached the end of this tutorial and the end of the “Phase 1 - K8s operators on your local workstation” series.

In this tutorial you have learnt how to:

  • Find the operations code inside of the operator

Where to go from here?