MicroK8s

  • Canonical Kubernetes
Channel Revision Published Runs on
latest/edge 236 09 Jan 2024
Ubuntu 22.04 Ubuntu 20.04
latest/edge 235 09 Jan 2024
Ubuntu 22.04 Ubuntu 20.04
latest/edge 234 09 Jan 2024
Ubuntu 22.04 Ubuntu 20.04
latest/edge 233 09 Jan 2024
Ubuntu 22.04 Ubuntu 20.04
latest/edge 232 09 Jan 2024
Ubuntu 22.04 Ubuntu 20.04
legacy/stable 124 17 Aug 2023
Ubuntu 22.04 Ubuntu 20.04
legacy/stable 121 17 Aug 2023
Ubuntu 22.04 Ubuntu 20.04
legacy/edge 124 10 Aug 2023
Ubuntu 22.04 Ubuntu 20.04
legacy/edge 125 10 Aug 2023
Ubuntu 22.04 Ubuntu 20.04
legacy/edge 123 10 Aug 2023
Ubuntu 22.04 Ubuntu 20.04
legacy/edge 122 10 Aug 2023
Ubuntu 22.04 Ubuntu 20.04
legacy/edge 121 10 Aug 2023
Ubuntu 22.04 Ubuntu 20.04
1.28/stable 213 20 Sep 2023
Ubuntu 22.04 Ubuntu 20.04
1.28/edge 218 19 Sep 2023
Ubuntu 22.04 Ubuntu 20.04
1.28/edge 217 19 Sep 2023
Ubuntu 22.04 Ubuntu 20.04
1.28/edge 216 19 Sep 2023
Ubuntu 22.04 Ubuntu 20.04
1.28/edge 215 19 Sep 2023
Ubuntu 22.04 Ubuntu 20.04
1.28/edge 213 19 Sep 2023
Ubuntu 22.04 Ubuntu 20.04
juju deploy microk8s --channel edge
Show information

Platform:

Ubuntu
22.04 20.04

This guide explains how to deploy a MicroK8s cluster and add it as a second cloud on your Juju controller, so that you can deploy Kubernetes workloads.

Requirements

  • An existing bootstrapped Juju controller on a cloud like AWS, Azure, OpenStack, LXD, etc

Steps

Deploy Cluster

Create a new model microk8s and deploy a 3-node cluster:

juju add-model microk8s
juju deploy microk8s -n 3 --config hostpath_storage=true --constraints 'mem=4G root-disk=20G'

Then, make sure to expose the microk8s application so that the Juju controller can reach the Kubernetes cluster:

juju expose microk8s

Wait until the cluster is deployed. The juju status should look like this:


Model     Controller  Cloud/Region   Version  SLA          Timestamp
microk8s  zs          zerostack/KHY  2.9.38   unsupported  01:41:13+03:00

App       Version  Status  Scale  Charm     Channel  Rev  Exposed  Message
microk8s           active      3  microk8s            77  yes      node is ready

Unit          Workload  Agent  Machine  Public address  Ports      Message
microk8s/30   active    idle   0        172.16.100.226  16443/tcp  node is ready
microk8s/31*  active    idle   1        172.16.100.18   16443/tcp  node is ready
microk8s/33   active    idle   2        172.16.100.111  16443/tcp  node is ready

Machine  State    Address         Inst id                               Series  AZ    Message
0        started  172.16.100.226  795b9667-fd5d-4ff4-8c42-e2de40e581c5  focal   nova  ACTIVE
1        started  172.16.100.18   27a00794-d77d-4aae-ab9c-18032e293085  focal   nova  ACTIVE
2        started  172.16.100.111  584ad91e-5ae7-4e1a-9a2c-6a4cc24d8ee2  focal   nova  ACTIVE

Add Kubernetes cluster as a cloud on the Juju controller

Retrieve the kubeconfig for the cluster with the following command:

# Juju 2.9
kubeconfig="$(juju run --unit microk8s/leader -- microk8s config)"

# Juju 3.1
kubeconfig="$(juju exec --unit microk8s/leader -- microk8s config)"

Then, create a microk8s-cloud cloud on your Juju controller with:

controller="$(juju controller-config controller-name)"
echo "$kubeconfig" | juju add-k8s microk8s-cloud --controller "$controller"

If successful, you should see output like the following:

k8s substrate "microk8s/localhost" added as cloud "microk8s-cloud" on controller zs.

Finally, check the configured clouds on the controller using juju clouds. The output should look like this:

Clouds available on the controller:
Cloud           Regions  Default    Type
microk8s-cloud  1        localhost  k8s
zerostack       1        KHY        openstack

Deploy Kubernetes charms

Now that the Juju controller is aware of our cluster, we can deploy Kubernetes workloads like this:

Create a model prometheus using the microk8s-cloud cloud.

juju add-model prometheus microk8s-cloud

Then, deploy prometheus-k8s:

juju deploy prometheus-k8s

Watch the progress of the deployment with juju status. After a while, it should look like this:

Model       Controller  Cloud/Region              Version  SLA          Timestamp
prometheus  zs          microk8s-cloud/localhost  2.9.38   unsupported  01:57:38+03:00

App         Version  Status      Scale  Charm           Channel  Rev  Address         Exposed  Message
prometheus  2.44.0   active          1  prometheus-k8s  edge     130  10.152.183.86   no

Unit           Workload  Agent  Address       Ports  Message
prometheus/0*  active    idle   10.1.5.148

Help improve this document in the forum (guidelines). Last updated 1 year, 2 months ago.