Development Setup

Charms created with the Charmed Operator Framework are able to operate across a wide variety of infrastructure. Before we start, you’ll need access to a machine with snapd installed. If you’re using Ubuntu, you’ve probably already got this installed. There are install instructions for most Linux distributions in the Snapcraft docs. This guide will walk through the installation of the following tools to get you started with charm development:

  • Multipass - a lightweight Ubuntu virtual machine manager (optional)
  • MicroK8s - a low-ops Kubernetes distribution we’ll use for testing our Charmed Operator
  • Juju - a Charmed Operator Lifecycle Manager (OLM), used for deploying and managing operators
  • Charmcraft - Developer tooling for creating, building and publishing Charmed Operators

Multipass (optional)

Multipass provisions Ubuntu virtual machines on-demand on any workstation. Whether you’re using a Windows, macOS or Linux machine, Multipass will provision a fresh new Ubuntu VM using the most appropriate hypervisor for your platform. If you’re working across multiple versions of Juju, or just want to keep your development environment separate, you can use Multipass to do that quickly and easily:

# Install Multipass
$ sudo snap install --classic multipass

# Launch a fresh new VM with 4 cores, 8GB RAM and a 20GB disk
$ multipass launch --cpus 4 --mem 8G --disk 20G --name charm-dev

# Get a shell in the new VM and continue the setup
$ multipass shell charm-dev

Once your VM is up and running, if you’d prefer to work in an editor on your local machine, you can just mount your charm repository into the VM and work on it locally using multipass mount.

MicroK8s

MicroK8s is a low-ops, minimal production Kubernetes for devs, cloud, clusters, workstations, Edge and IoT. The steps below will get you up and running:

# Install MicroK8s package
$ sudo snap install --classic microk8s

# Add your user to the `microk8s` group for unprivileged access
$ sudo usermod -aG microk8s $(whoami)

# Wait for MicroK8s to finish initialising
$ sudo microk8s status --wait-ready

# Enable the 'storage' and 'dns' addons
# (required for the Juju controller)
$ sudo microk8s enable storage dns ingress

# Alias kubectl so it interacts with MicroK8s by default
$ sudo snap alias microk8s.kubectl kubectl

# Ensure your new group membership is apparent in the current terminal
# (Not required once you have logged out and back in again)
$ newgrp microk8s

Charmcraft

Charmcraft is a command line tool used alongside the Charmed Operator Framework to create, build, and publish charms. It is installed using snap:

$ sudo snap install charmcraft

Juju

Juju can also be installed using snap:

$ sudo snap install juju --classic

In order to test our Charmed Operator, we need to first bootstrap a controller onto our Kubernetes instance, and then create a model for our deployment:

# 'micro' is a user-specified name for the controller.
# You can leave this blank, or specify your own name
$ juju bootstrap microk8s micro

# 'development' is also user-specified.
$ juju add-model development

Creating a model on a Kubernetes controller creates a Kubernetes namespace, and provides a workspace into which Juju can deploy Charmed Operators.

Non-Kubernetes Charm Development

If you are looking to develop a charm for non-Kubernetes infrastructure, Juju can be easily set up to work with a local LXD provider. Those instructions can be found here: Using LXD with Juju

Advanced charm development may require integrating with larger deployments. In those cases, a local MicroK8s or LXD provider may not be sufficient. Instructions for configuring Juju to work with larger deployments can be found here: