Start K8s with microk8s

Tharanga Rajapaksha
4 min readAug 15, 2019

--

Microk8s is a simplest way to launch single node kubernetes environment for testing and learning perposes any devops. This is fast, small, cheap k8s for CI/CD.

snaps are software bundles come with all it’s dependencies. They update automatically and roll back gracefully. Snaps are discoverable and installable from snap store.

Install snap in linux dabians.

sudo apt update
sudo apt install snapd

Install microk8s.

sudo snap install microk8s --classic

Following url is the user guide for micro k8s.

At any point you can check MicroK8s’ availability with:

$ sudo microk8s.stauts

To avoid colliding with a kubectl already installed and to avoid overwriting any existing Kubernetes configuration file, MicroK8s adds a microk8s.kubectl command, configured to exclusively access the new MicroK8s install. When following instructions online, make sure to prefix kubectl with microk8s..

$ microk8s.kubectl get nodes
$ microk8s.kubectl get services

If you do not already have a version of kubectl installed you can alias microk8s.kubectl to kubectl using the following command:

$ snap alias microk8s.kubectl kubectl

This measure can be safely reverted at any time by running:

snap unalias kubectl

Kubernetes add-ons

MicroK8s installs a barebones upstream Kubernetes. This means just the api-server, controller-manager, scheduler, kubelet, cni, kube-proxy are installed and run. Additional services like kube-dns and dashboard can be run using the microk8s.enable command.

microk8s.enable dns dashboard

These add-ons can be disabled at anytime using the disable command

microk8s.disable dashboard dns

List of available add-ons

  • dns: Deploy CoreDNS. This add-on may be required by others thus we recommend you always enable it. In environments where the external dns servers 8.8.8.8 and 8.8.4.4 are blocked you will need to update the upstream dns servers in microk8s.kubectl -n kube-system edit configmap/coredns after enabling the add-on.
  • dashboard: Deploy Kubernetes dashboard as well as Grafana and InfluxDB. To access Grafana point your browser to the url reported by microk8s.kubectl cluster-info. Access the dashboard with the default token found with microk8s.kubectl -n kube-system get secret and microk8s.kubectl -n kube-system describe secret default-token-{xxxx}.
  • storage: Create a default storage class. This storage class makes use of the hostpath-provisioner pointing to a directory on the host. Persistent volumes are created under ${SNAP_COMMON}/default-storage. Upon disabling this add-on you will be asked if you want to delete the persistent volumes created.
  • ingress: Create an ingress controller.
  • gpu: Expose GPU(s) to MicroK8s by enabling the nvidia runtime and nvidia-device-plugin-daemonset. Requires NVIDIA drivers to be already installed on the host system.
  • istio: Deploy the core Istio services. You can use the microk8s.istioctl command to manage your deployments.
  • registry: Deploy a private image registry and expose it on localhost:32000. The storage add-on will be enabled as part of this add-on. See the registry documentation for more details.
  • metrics-server: Deploy the Metrics Server.
  • prometheus: Deploy the Prometheus Operator v0.25.
  • fluentd: Deploy the Elasticsearch-Kibana-Fluentd logging and monitoring solution.
  • jaeger: Deploy the Jaeger Operator v1.8.2 in the “simplest” configuration.
  • linkerd: Deploy linkerd2 Linkerd service mesh. By default proxy auto inject is not enabled. To enable auto proxy injection, simply use microk8s.enable linkerd:proxy-auto-inject. If you need to pass more arguments, separate them with ; and enclose the addons plus arguments with double quotes. For example: microk8s.enable "linkerd:proxy-auto-inject;tls=optional;skip-outbound-ports=1234,3456". Use microk8s.linkerd command to interact with Linkerd.
  • rbac: Enable RBAC (Role-Based Access Control) authorisation mode. Note that other add-ons may not work with RBAC enabled.
  • knative: Enable Knative with microk8s.enable knative.

How to use istilo with microk8s

Configuring MicroK8s services

The following systemd services will be running in your system:

  • snap.microk8s.daemon-apiserver, is the kube-apiserver daemon started using the arguments in ${SNAP_DATA}/args/kube-apiserver
  • snap.microk8s.daemon-controller-manager, is the kube-controller-manager daemon started using the arguments in ${SNAP_DATA}/args/kube-controller-manager
  • snap.microk8s.daemon-scheduler, is the kube-scheduler daemon started using the arguments in ${SNAP_DATA}/args/kube-scheduler
  • snap.microk8s.daemon-kubelet, is the kubelet daemon started using the arguments in ${SNAP_DATA}/args/kubelet
  • snap.microk8s.daemon-proxy, is the kube-proxy daemon started using the arguments in ${SNAP_DATA}/args/kube-proxy
  • snap.microk8s.daemon-containerd, is the containerd daemon started using the configuration in ${SNAP_DATA}/args/containerd and ${SNAP_DATA}/args/containerd-template.toml.
  • snap.microk8s.daemon-etcd, is the etcd daemon started using the arguments in ${SNAP_DATA}/args/etcd

Normally, ${SNAP_DATA} points to /var/snap/microk8s/current.

To reconfigure a service you will need to edit the corresponding file and then restart the respective daemon. For example:

echo '-l=debug' | sudo tee -a /var/snap/microk8s/current/args/containerd
sudo systemctl restart snap.microk8s.daemon-containerd.service

Stopping and restarting MicroK8s

You may wish to temporarily shutdown MicroK8s when not in use without un-installing it.

MicroK8s can be shutdown with:

microk8s.stop

MicroK8s can be restarted later with:

microk8s.start

Before removing MicroK8s, use microk8s.reset to stop all running pods.

microk8s.reset
snap remove microk8s

Following url describe both minikube and microk8s clearly.

--

--