Juju 101 - Scale [2/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 - Ready! Steady! Go.

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:

  • Map application units and operators to Kubernetes pods
  • Scale an application both up and down in how many pods it has running

You will only need:

  • A machine with 8 GB of RAM
  • Microk8s and Juju installed
  • Juju controller bootstrapped on MicroK8s
  • Prometheus deployed to MicroK8s with an operator

Scale the application

Duration: 10:00

Operators and Juju OLM provide lifecycle management capabilities so that applications can be scaled out and back in a fully automated way.

In the following steps, we will scale our first application with an operator.

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  11:00:06+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.51  9090/TCP

Let’s also check how many pods are running there inside the “monitoring” namespace on Kubernetes:

$ microk8s.kubectl get pods -n monitoring
NAME                         	READY   STATUS	RESTARTS   AGE
modeloperator-6446c5df98-lzfr8  1/1 	Running   0      	4m56s
prometheus-k8s-operator-0      	1/1 	Running   0      	4m9s
prometheus-k8s-0               	1/1 	Running   0      	3m54s

Now we can scale up prometheus application to multiple pods:

$ juju scale-application prometheus-k8s 3
prometheus-k8s scaled to 3 units

The change is immediately reflected in the output of the “juju status” command. Additional units of the prometheus application are being created:

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

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

Unit               Workload  Agent  Address     Ports     Message
prometheus-k8s/0*  active    idle   10.1.98.51  9090/TCP
prometheus-k8s/1   waiting   idle   10.1.98.5   9090/TCP  waiting for container
prometheus-k8s/2   waiting   idle   10.1.98.58  9090/TCP  waiting for container

After a moment you should be able to see the following output from the kubectl command:

$ microk8s.kubectl get pods -n monitoring
NAME                         	READY   STATUS	RESTARTS   AGE
modeloperator-6446c5df98-lzfr8  1/1 	Running   0      	5m58s
prometheus-k8s-operator-0      	1/1 	Running   0      	5m11s
prometheus-k8s-0               	1/1 	Running   0      	4m56s
prometheus-k8s-2               	1/1 	Running   0      	30s
prometheus-k8s-1               	1/1 	Running   0      	30s

From the above output, we can see that there is still a single pod running the operator, and there are now 3 pods running the application.

We can use the same mechanism for scaling the application back down again:

$ juju scale-application prometheus-k8s 2
prometheus-k8s scaled to 2 units

While it is shutting down you can see the application unit being removed from the Juju model:

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

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

Unit               Workload     Agent       Address       Ports     Message
prometheus-k8s/0*  active       idle        10.1.98.51    9090/TCP
prometheus-k8s/1   active       idle        10.1.98.5     9090/TCP
prometheus-k8s/2   terminated	executing	10.1.236.207  9090/TCP  (remove)

And finally, the unit has been terminated and is no longer present:

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

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

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

The same status is reflected in the kubectl command output:

$ microk8s.kubectl get pods -n monitoring
NAME                         	READY   STATUS	RESTARTS   AGE
modeloperator-6446c5df98-lzfr8  1/1 	Running   0      	7m9s
prometheus-k8s-operator-0      	1/1 	Running   0      	7m2s
prometheus-k8s-0               	1/1 	Running   0      	6m48s
prometheus-k8s-2               	1/1 	Running   0      	2m22s

Next steps

Duration: 2:00

Congratulations! You have reached the end of this tutorial.

You can now move to the next tutorial - 3. Configuration or explore other tutorials.

In this tutorial you have learnt how to:

  • Map application units and operators to Kubernetes pods
  • Scale an application both up and down in how many pods it has running

Where to go from here?

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