Set up your development environment

From zero to hero: Write your first Kubernetes charm > Set up your development environment

See previous: Study your application

In this chapter of the tutorial you will set up your development environment.

You will need a charm directory, the various tools in the charm SDK, Juju, and a Kubernetes cloud. And it’s a good idea if you can do all your work in an isolated development environment.

You can get all of this by following our generic development setup guide, with some annotations.

See Set up your development environment automatically, with the following changes:

  • At the directory step, call your directory fastapi-demo.
  • At the VM setup step, call your VM charm-dev and also set up Docker:
    1. sudo addgroup --system docker
    2. sudo adduser $USER docker
    3. newgrp docker
    4. sudo snap install docker.
  • At the cloud selection step, choose microk8s.
  • At the mount step: Make sure to read the box with tips on how to edit files locally while running them inside the VM!

    All set!

Congratulations, your development environment is now ready!

See next: Create a minimal Kubernetes charm

Contributors: @acsgn, @beliaev-maksim, @bschimke95, @tony-meyer, @tmihoc, @tphan025

I like this, but the process of setting up your environment would differ if you would go for a VM charm on lets say LXD. I’m trying to reuse this step for LXD but realize that the extra requirement on K8 makes this guide not reusable and places on the reader/user to also implicitly accept to have to learn about K8 before starting development of charms.

Can this step be made either neutral to K8/lxd/vm - or do we divert between LXD-VM charms even at this stage?

Oh, and another note is that why is “lxd init --auto” in here for this purpose?


1 Like

@erik-lonroth This file was intended as a chapter in the Write a Kubernetes Charm tutorial.

1 Like

can you please put a header that this is a part of Zero to Hero ?

@beliaev-maksim How about a breadcrumb (see above)?

Note that when published on the website the side Navigation will show this doc nested under Tutorial > Write your first Kubernetes charm (or something like that; as opposed to Tutorial > Write your first machine charm).

1 Like

I’m basically repeating all of the above for LXD as we speak.

This is what it looks like:

Spawn a new VM on LXD

lxc launch ubuntu:22.04 charm-dev --vm

Get a shell on the vm:

lxc shell charm-dev

Disable ipv4 for apt if you don’t have ipv6.

 root@charm-dev:~# sudo echo Acquire::ForceIPv4 "true"; > /etc/apt/apt.conf.d/99force-ipv4

Install juju and charmcraft and initialize lxd

 root@charm-dev:~# sudo snap install juju --classic
 root@charm-dev:~# sudo snap install charmcraft --classic
 root@charm-dev:~# lxd init --auto

Validate that you can see your new lxd cloud named(also called remote in lxd terms)

lxc remote list

Juju has picked this cloud up and named it “localhost”.

 root@charm-dev:~# juju clouds --client
Only clouds with registered credentials are shown.
There are more clouds, use --all to see them.
You can bootstrap a new controller using one of these clouds...

Clouds available on the client:
Cloud      Regions  Default    Type  Credentials  Source    Description
localhost  1        localhost  lxd   1            built-in  LXD Container Hypervisor

Create a controller on the localhost cloud

 root@charm-dev:~# juju bootstrap localhost tutorial-controller
Creating Juju controller "tutorial-controller" on localhost/localhost
Looking for packaged Juju agent version 2.9.38 for amd64
Located Juju agent version 2.9.38-ubuntu-amd64 at
To configure your system to better support LXD containers, please see:
Launching controller instance(s) on localhost/localhost...
 - juju-3a5da3-0 (arch=amd64)                 
Installing Juju agent on bootstrap instance
Fetching Juju Dashboard 0.8.1
Waiting for address
Attempting to connect to fd42:e802:396b:494a:216:3eff:fe4b:8fc7:22
Attempting to connect to
Connected to fd42:e802:396b:494a:216:3eff:fe4b:8fc7
Running machine configuration script...
Bootstrap agent now started
Contacting Juju controller at to verify accessibility...
Bootstrap complete, controller "tutorial-controller" is now available
Controller machines are in the "controller" model
Initial model "default" added

Validate that the juju client can talk to your localhost cloud.

root@charm-dev:~# juju status
Model    Controller           Cloud/Region         Version  SLA          Timestamp
default  tutorial-controller  localhost/localhost  2.9.38   unsupported  15:26:30Z

Model "admin/default" is empty.

With that, you have a juju-cloud and juju-controller ready for development.

1 Like

Some users, including myself, love the CLI autocompletion feature very much. However, this is not working in juju 3+ as it’s reported here. One temporary solution is the following:

cp /snap/juju/current/bash_completions/juju       /usr/share/bash-completion/completions/

It would be great if this part can be included in this tutorial.

1 Like

# Install Microk8s from snap:
sudo snap install microk8s --channel 1.25-strict/stable

1.25 is EOL now. Is there a plan to update software versions to the current releases, please?

Hi @boggy , sorry for the late reply. Thanks for bringing this up – I will address it as part of a bigger update to the tutorial – one where we switch to the charm-dev Multipass VM blueprint (which will give you a VM with everything you’ll need to start developing preinstalled), where we adopt charmcraft init (it’s one of the main things the SDK has to offer, so we should feature it, even if it keeps changing (the original rationale for not using it)), and where we replace metadata.yaml with charmcraft.yaml (since Chamcraft 2.5, the only yaml file that the charmer is supposed to edit directly).

Section 8 Publish your charm on Charmhub uses docker which is not included in charm-dev nor in this documentation page.

I suggest adding a subsection as follows.

Install Docker

On your Ubuntu VM, install Docker:

# Create 'docker' group and add the 'ubuntu' user:
sudo groupadd docker
sudo usermod -a -G docker ubuntu
newgrp docker

# Install 'docker' from snap:
sudo snap install docker

Read more: Docker

It would be good to add a section to guide the user to check if their version of tox installed is supported by the tutorial, or at least specify which versions of tox are supported.

Using the charm-dev blueprint of multipass installs tox@v3.21.4-1ubuntu1. However, the tutorial uses the tox_root variable on its tox.ini file, which is only supported on tox@v4 or newer versions. Thanks to this, an user would need to uninstall the tox package, then reinstall it using pipx. A heads-up about the minimum supported version of tox would be nice in this case.

1 Like

Hi @beliaev-maksim, I would like to extend this post with using the charm-dev blueprint directly for my onboarding documentation task. I would also include steps from José for tox and Alex for docker. Is this okay? Should I directly edit this document or share you a draft, so that you can update it? Thanks!

Hi @acsgn , I’m the technical author for docs. While @beliaev-maksim was instrumental in getting this tutorial going, and we will continue to seek his input, the primary way to make further changes would be to have a chat with me.

First, thanks for your willingness to contribute.

Regarding the changes you propose: In the machine version of this tutorial we already use the charm-dev blueprint ( we link to the how-to guide where that setup is documented: Juju | Set up your development environment ). I think we are now ready to do this for the Kubernetes tutorial as well.

Regarding tox and docker. Insofar as I know, tox comes preinstalled with the charm-dev blueprint, but docker does not. I guess we could amend the how-to guide to tell people to install it too. (Or, if it’s something all charmers could use: let’s amend the blueprint itself.)

The plan of action then is:

  • Update the blueprint / how-to guide with docker.
  • Update this chapter of the tutorial (that we are commenting on now) to simply link to the automatic setup section in the how-to guide, on the model of the setup section in the tutorial for machine charms.

You may edit the document directly, but it’s usually a good idea to set up a quick meeting to discuss the draft with me first.

1 Like

Hi, thanks for the reply. I had a similar thing in my mind, keeping both automated and manual installation steps. I would like to have a chat with you and maybe also with @beliaev-maksim regarding the action plan.

1 Like