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:
- Charmcraft - Developer tooling for creating, building and publishing Charmed Operators
- Juju - a Charmed Operator Lifecycle Manager (OLM), used for deploying and managing operators
- Multipass - a lightweight Ubuntu virtual machine manager (optional)
- MicroK8s - a low-ops Kubernetes distribution we’ll use for testing our Charmed Operator (optional if developing a Charmed Operator for Kubernetes)
Charmcraft is a command line tool used alongside the Charmed Operator Framework to create, build, and publish charms. It is installed using
$ sudo snap install charmcraft
For more information about installing Charmcraft, see Installing Charmcraft.
Charmcraft depends on LXD to build the charms in a container matching the target base(s). To set up LXD manually:
$ sudo snap install lxd $ sudo adduser $USER lxd $ newgrp lxd $ lxd init --auto
Juju can also be installed using
$ sudo snap install juju --classic
If you’d like to create an isolated development environment, or you are running a different operating system or distribution and you’d like to ensure you can follow the documentation without any hurdles, 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 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
MicroK8s (optional) is a low-ops, minimal production Kubernetes for devs, cloud, clusters, workstations, Edge, and IoT. The steps below will get you up and running if you are developing a Charmed Operator for Kubernetes.
# Install MicroK8s package $ sudo snap install --classic microk8s # Add your user to the `microk8s` group for unprivileged access $ sudo adduser $USER microk8s # 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
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 # This will create a new namespace named `controller-micro` and # provision a pod which runs the Juju controller with an associated instance # of MongoDB $ 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. To learn more, see 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:
- MicroStack (All-in-one Openstack)
Last updated 1 year, 7 months ago.