Setup MicroK8s

Posted on November 12, 2019

How to build a developer kubernetes setup with MicroK8s

I needed a test kubernetes cluster to deploy my applications during the development. I have a Intel NUC which is perfect as small server and installed Ubuntu Server 19.10 and at the end of the installation the setup asked if I want to install MicroK8s.

As I have only installed a full featured kubernetes cluster on linux and on Windows I am using Docker Desktop for Windows with Kubernetes, I thought I give it a try.

It took a little while, but I ended up with a nice little kubernetes running which is perfect for my needs.

Install MicroK8s

This was done at the end of my Ubuntu Server installation. Have a look at the MicroK8s docs for other installations.

Enable RBAC

To be as similar as in the production system I want to enable rbac.

1
microk8s.enable rbac

Enable DNS

And also enable DNS

1
microk8s.enable dns

Enable Helm

All installatons in the kubernetes cluster I do with the help of Helm. MicroK8s has a helm addon which can be enabled with

1
microk8s.enable helm

After enabling helm, microk8s.helm ist the command to use. Before installing tiller in the cluster a service account and role binding must be applied to the cluster.

1
nano helm-rbac.yaml

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system

This file has to be applied to the cluster.

1
microk8s.kubectl apply -f helm-rbac.yaml

After the conditions were created, helm could be initialized.

1
microk8s.helm init --service-account tiller

Install MetalLB

LoadBalancers are an important when running a cluster. One of the ways to run a bare metal cluster is with the help of MetalLB.

1
microk8s.kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.8.3/manifests/metallb.yaml

Configure the MetalLB with the available IPs in the network.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 192.168.0.100-192.168.0.200    

 

1
microk8s.kubectl apply -f metallb-conf.yaml

Install NGINX-Ingress

Helm is installed, a loadbalancer is running. Now it is time for the ingress controller as the last piece of my cluster.

1
microk8s.helm install stable/nginx-ingress --name my-nginx --set rbac.create=true

Cluster is running

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
microk8s.kubectl get all --all-namespaces
NAMESPACE        NAME                                                          READY   STATUS    RESTARTS   AGE
default          pod/my-nginx-nginx-ingress-controller-cfc8ccf95-8fz6z         1/1     Running   0          91m
default          pod/my-nginx-nginx-ingress-default-backend-6957b79cd7-jj28n   1/1     Running   0          91m
kube-system      pod/coredns-9b8997588-9wnvc                                   1/1     Running   5          27h
kube-system      pod/dashboard-metrics-scraper-566cddb686-b9hvc                1/1     Running   4          27h
kube-system      pod/heapster-v1.5.2-5c58f64f8b-l6rh6                          4/4     Running   19         27h
kube-system      pod/kubernetes-dashboard-678b7d865c-cm78b                     1/1     Running   4          27h
kube-system      pod/monitoring-influxdb-grafana-v4-6d599df6bf-g9xjt           2/2     Running   8          27h
kube-system      pod/tiller-deploy-79c578486f-2gfxt                            1/1     Running   0          92m
metallb-system   pod/controller-65895b47d4-wtxwc                               1/1     Running   2          26h
metallb-system   pod/speaker-65t9s                                             1/1     Running   2          26h

NAMESPACE     NAME                                             TYPE           CLUSTER-IP       EXTERNAL-IP       PORT(S)                      AGE
default       service/kubernetes                               ClusterIP      10.152.183.1     <none>            443/TCP                      30h
default       service/my-nginx-nginx-ingress-controller        LoadBalancer   10.152.183.8     192.168.0.100     80:32021/TCP,443:31373/TCP   91m
default       service/my-nginx-nginx-ingress-default-backend   ClusterIP      10.152.183.171   <none>            80/TCP                       91m
kube-system   service/dashboard-metrics-scraper                ClusterIP      10.152.183.223   <none>            8000/TCP                     27h
kube-system   service/heapster                                 ClusterIP      10.152.183.85    <none>            80/TCP                       27h
kube-system   service/kube-dns                                 ClusterIP      10.152.183.10    <none>            53/UDP,53/TCP,9153/TCP       27h
kube-system   service/kubernetes-dashboard                     ClusterIP      10.152.183.180   <none>            443/TCP                      27h
kube-system   service/monitoring-grafana                       ClusterIP      10.152.183.45    <none>            80/TCP                       27h
kube-system   service/monitoring-influxdb                      ClusterIP      10.152.183.61    <none>            8083/TCP,8086/TCP            27h
kube-system   service/tiller-deploy                            ClusterIP      10.152.183.176   <none>            44134/TCP                    92m

NAMESPACE        NAME                     DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR                 AGE
metallb-system   daemonset.apps/speaker   1         1         1       1            1           beta.kubernetes.io/os=linux   26h

NAMESPACE        NAME                                                     READY   UP-TO-DATE   AVAILABLE   AGE
default          deployment.apps/my-nginx-nginx-ingress-controller        1/1     1            1           91m
default          deployment.apps/my-nginx-nginx-ingress-default-backend   1/1     1            1           91m
kube-system      deployment.apps/coredns                                  1/1     1            1           27h
kube-system      deployment.apps/dashboard-metrics-scraper                1/1     1            1           27h
kube-system      deployment.apps/heapster-v1.5.2                          1/1     1            1           27h
kube-system      deployment.apps/kubernetes-dashboard                     1/1     1            1           27h
kube-system      deployment.apps/monitoring-influxdb-grafana-v4           1/1     1            1           27h
kube-system      deployment.apps/tiller-deploy                            1/1     1            1           92m
metallb-system   deployment.apps/controller                               1/1     1            1           26h

NAMESPACE        NAME                                                                DESIRED   CURRENT   READY   AGE
default          replicaset.apps/my-nginx-nginx-ingress-controller-cfc8ccf95         1         1         1       91m
default          replicaset.apps/my-nginx-nginx-ingress-default-backend-6957b79cd7   1         1         1       91m
kube-system      replicaset.apps/coredns-9b8997588                                   1         1         1       27h
kube-system      replicaset.apps/dashboard-metrics-scraper-566cddb686                1         1         1       27h
kube-system      replicaset.apps/heapster-v1.5.2-5c58f64f8b                          1         1         1       27h
kube-system      replicaset.apps/kubernetes-dashboard-678b7d865c                     1         1         1       27h
kube-system      replicaset.apps/monitoring-influxdb-grafana-v4-6d599df6bf           1         1         1       27h
kube-system      replicaset.apps/tiller-deploy-79c578486f                            1         1         1       92m
metallb-system   replicaset.apps/controller-65895b47d4                               1         1         1       26h