This is a guest post, originally posted on Konstantinos Tsakalozos’ personal blog, adapted and reproduced here with his permission. Konstantinos is a Staff Engineer at Canonical and the Software Lead behind MicroK8s.
MicroK8s addons, extra services which can be added to your bare-bones cluster, are a great favourite with users as they allow you to bring diverse DevOps operations under the same homogeneous UX. Do you want to apply the CoreDNS manifest, reconfigure kubelet and restart the nodes on a cluster? microk8s
is what you run. Do you want to install a hostpath storage provisioner and fire up Portainer? microk8s enable portainer
does exactly that. There are no particular restrictions to what an addon can do – if you can do it in Kubernetes, you can write an addon to do it too.
With the upcoming v1.24 release, we have opened up the addons framework to the public. We have made sure software vendors and enthusiasts can create and use their own addon repositories and edit in place any available addons within a running cluster.
In what follows we look into :
At the time of this writing, the v1.24 release is in release candidate, therefore you would need to install MicroK8s from the latest/edge channel to get the latest updates on the addons framework:
sudo snap install microk8s --classic --channel=latest/edge
With the microk8s status
command you can see the list of the available addons:
To enable an addon, you need to call microk8s enable
followed by the name of the addon, eg microk8s enable dns
. Similarly, microk8s disable
will disable the named addon and uninstall it.
In the example output above you may notice that the description of each addon starts with “core”. This indicates the repository the addon is available from. Core addons are the ones maintained and supported by the MicroK8s team. In addition to the core addons we ship MicroK8s with a set of community-maintained addons. To display those you just need to run the command microk8s enable community
:
As we will see, adding, removing and updating repositories is done through the microk8s addons repo command. microk8s enable community
is a shortcut to get the community contributions visible without knowing the exact URL of the respective repo.
Addon repositories are git projects which are cloned under /var/snap/microk8s/common/addons . For example, the core repository is found in the /var/snap/microk8s/common/addons/core directory inside which there is a folder called addons with all its addons.
Notice the enable and disable executable files found on each addon? These are the hook scripts each addon implements and the microk8s enable and microk8s disable commands expect to be able to find and call.
It is possible an addon does 95% of what you want but not exactly what you need. There is nothing stopping you from editing the respective enable hook to match your needs. Although there are no restrictions on the language these hooks are written in, often they come as Bash or Python scripts.
Try this yourself. Edit /var/snap/microk8s/common/addons/helm3/enable and set the HELM_VERSION to “v3.7.0”. Save the enable file and call microk8s enable helm3
. Yes, it is that simple!
The most exciting feature of the v1.24 release is the option to add 3rd-party repositories to a MicroK8s cluster.
To bootstrap the repository authoring process the MicroK8s team provides a template repository with two example addons (in python and bash) to fork. That repository can be found at https://github.com/canonical/microk8s-addons-repo-template. The README.md and HACKING.md pages will guide you through this task.
Here, we will briefly touch on the main steps you need to take:
Fork the template repository. If you are logged into Github just click on the “Use this template” button and fill out the “new repository” form.
The addons.yaml at the top level of each repo holds the list of the addons. Replace this list with the list of addons you will be shipping. Each entry has the following fields:
Create a directory under addons named after the addon you would be implementing.
In that directory, add two executable files named enable and disable. These executables can be written in any language and are called by the microk8s enable/disable commands.
At this point, you are able to add your repository into MicroK8s with something similar to:
sudo microk8s addons repo add fantastic https://github.com/myorg/myrepo
fantastic is the ID you give to your repository. From this point on this ID is used to reference the repo when updating and removing it, eg:
sudo microk8s addons repo update fantastic
sudo microk8s addons repo remove fantastic
Knowing that addons are git projects allows for a number of workflows while developing:
Using the –reference flag you can add a repository and point to a branch/tag:
You can also add a git project as a repository that is local on your host:
Use microk8s addons repo update to fetch the latest changes pushed on the repository you are working on. Alternatively, you can clone a git repository directly under /var/snap/microk8s/common/addons/ and MicroK8s will pick it up as a repository.
MicroK8s ships with both the core and community addons. In order not to clutter the user output the community addons are not visible by default. One needs to microk8s enable community or to add the community repository as any other repository:
sudo microk8s addons repo add community https://github.com/canonical/microk8s-addons.git
In order to promote your work, you can fork the community repository, add your addon, and place a PR against the upstream repo. Some things you should be aware of:
One of the most powerful features of MicroK8s, the addons, is now free and available to everyone. We hope you will enjoy this freedom, and look forward to seeing what addons you will come up with!
Do not hesitate to reach out if you need any help in your journey and feel free to check out the MicroK8s website for more information.
Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…
Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…
At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…
I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…
Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…
Now I want to share the DNS server installation process on your Ubuntu 20.04 server.…