Producing a custom MicroK8s snap involves setting up your workstation to be able to build snaps, fetching the source code, customizing the snap and finally building it. Here we go through the build steps of a snap that would feature Kubernetes version v1.27.2 and a non standard addons repository.
Setting up the build environment
Please follow the snapcraft setup instractions to install the snapcraft tool as well as a build backend, either Multipass or LXC. On Ubuntu typically this would involve:
sudo snap install snapcraft --classic
and
sudo snap install multipass
Fetch and customise the MicroK8s source
To get the source code you need to clone the MicroK8s git repository and checkout the branch we are interested in. In our case, that we want to package the v1.27.2 Kubernetes we need to checkout the 1.27 branch:
git clone https://github.com/canonical/microk8s
cd microk8s
git checkout 1.27
The components we build during the snap creation can be found under build-scripts/components
. We are interested in changing the Kubernetes version so we need to edit
build-scripts/components/kubernetes/version.sh
and set the KUBE_VERSION
to v1.27.2
.
In the list of addon repositories we want to remove the community
repo and include a repository with AWS integrations. To this end we edit build-scripts/addons/repositories.sh
and set ADDONS_REPOS
to be:
ADDONS_REPOS="
core,https://github.com/canonical/microk8s-core-addons,1.27
eksd,https://github.com/canonical/microk8s-aws-addons,1.25-eksd
"
Build and deploy
From the root of the source code we trigger a build with:
snapcraft
A Multipass VM should spawn to host the build process. At the end of the build process we should have a microk8s_v1.27.2_amd64.snap
package that can be installed with:
sudo snap install ./microk8s_v1.27.2_amd64.snap --classic --dangerous
References
- Snapcraft install guide, https://snapcraft.io/docs/snapcraft-setup
- Install Multipass, https://multipass.run/docs/installing-on-linux
- Buidling and testing MicroK8s, https://github.com/canonical/microk8s/blob/master/docs/build.md