Warning: This tutorial is outdated. Please use the Juju with MicroK8s tutorial instead.
microk8s is awsome
If you want to quickly and easily do some Kubernetes charm development, or hack on Juju’s Kubernetes support, do yourself a favour and snap install microk8s.
I have previously described how to run a Kubernetes demo on AWS. It’s great and all, but the time to bootstrap, deploy a Kubernetes bundle, and run the trust command to set up the necessary permissions means that you are waiting up to say 20 minutes to get started. And often, you’ll need to tear things down and start again as part of the development process. And you need to be online.
With microk8s, you have a local, fully compliant Kubernetes deployment with dynamic persistent volume support, and a running ingres controller.
Ensure microk8s is set up correctly
After installing mictok8s, you’ll want to enable dns and storage.
sudo snap install microk8s --edge --classic
microk8s.enable dns storage
I normally also alias microk8s.kubctl
:
sudo snap alias microk8s.kubectl mkubectl
Juju time!
You start by bootstrapping an LXD controller:
juju bootstrap lxd
Now, register your microk8s cloud with Juju and add a model:
microk8s.config | juju add-k8s k8stest
juju add-model test k8stest
That’s all the setup we need. In the time taken to bootstrap a LXd controller, we’re ready to deploy Kubernetes workloads with Juju.
Deploy mariadb
Let’s deploy mariadb. It requires storage, but microk8s has a storage class built in which will be used. To deploy with the default hostpath
storage and a 1GiB allocation:
juju deploy cs:~juju/mariadb-k8s
Or you may want to deploy with a smaller storage allocation, say 10MiB:
juju deploy cs:~juju/mariadb-k8s --storage database=10M
juju status
Model Controller Cloud/Region Version SLA Timestamp
test ian k8stest 2.5-beta1 unsupported 14:56:31+10:00
App Version Status Scale Charm Store Rev OS Address Charm version Notes
mariadb active 1 mariadb-k8s jujucharms 7 kubernetes 10.152.183.94
Unit Workload Agent Address Ports Message
mariadb/0* active idle 10.1.1.32 3306/TCP Started container
juju storage --filesystem
[Filesystems]
Unit Storage Id Provider id Mountpoint Size State Message
mariadb/0 database/0 0 database-0-mariadb-0 /var/lib/mysql 34MiB attached Successfully provisioned volume pvc-39a6de3a-b255-11e8-a2de-80fa5b27f2bf
The actual physical storage location is at /var/snap/microk8s/common/default-storage/
so you can easily inspect the files created by both the Juju mariadb operator and the database itself.
ls /var/snap/microk8s/common/default-storage/
database-0-mariadb-0-pvc-39a6de3a-b255-11e8-a2de-80fa5b27f2bf charm-operator-mariadb-0-pvc-33d08565-b255-11e8-a2de-80fa5b27f2bf
Full Reset
If for whatever reason you need to completely reset everything and want to start from scratch, it’s easy enough just to do:
juju kill-controller <name> -y -t 0
microk8s.reset
juju remove-cloud k8stest