I’ve toyed with Kubernetes in the past on my workstation however I never really did anything serious with the instance. I have two additional machines plus two Raspberry Pis I would love to get into a cluster eventually. But for now I would just like to get some working loads up on my workstation.

Examining the state

I originally installed Minikube on Ubuntu 18.04.2. A kubectl config get-contexsts returns a single context which looks local. However a kubectl get nodes returns a The connection to the server <IP>:6443 was refused - did you specify the right host or port?. A docker ps -a shows the containers for Kubernetes missing. I am guessing this was a botched uninstall while attempting to free space. Once I get that host configuration captured under Salt I would love to do a fresh install with a much larger root drive!

A quick search for minikube or kube returns turtles. A snap list does not return anything related, although interestingly there is a ngome-3-26-1604 snap in there. I wonder what that is attached too. Looks like I can get the size from du -hcs /var/lib/snapd/snaps or snap list --size. Although the --size option returned with a complaint about the flag. The snap files are regular files, so du just gives the total size for all images. Leaving just a ls -lah /var/lib/snapd/snaps. The Gnome 3 images are about 150M, so no where near as large as I was worried about.

At this point it really looks like I removed most of the minikube components. I’ll have to reinstall it now.

Installing Kubernetes

Hmm, looks like minikube actually drives a VirtualBox instance, even on a metal box. I would really like to find a solution which will run directly on the node.

The two options given on the official pages show either a Juju based install or microk8s. [Juju](https://en.wikipedia.org/wiki/Juju_(software) seems to compete the Configuration Management relam, so microk8s it is! Definitely not installed already.

Looks like Kubernetes 1.15 is out, so I am hoping I can run that. A sudo snap install microk8s --classic --channel=1.15/stable seemed to get it done. A microk8s.kubectl get nodes failed with a similar command as before. The microk8s.inspect shows:

FAIL: Service snap.microk8s.daemon-apiserver is not running

Looks like a possible root cause might be:

Aug 18 20:56:39 kal microk8s.daemon-apiserver[6004]: Error: failed to create listener: failed to listen on 127.0.0.1:8080: listen tcp 127.0.0.1:8080: bind: address already in use

This makes total sense since I already have something running on that port. Time to find out what this port is meant to be used for and how to reconfigure it. The port appears to be the target for the API server. I am wondering if I can reassign this to another number without too many problems.

Trying to fix the microk8s port

From a security standpoint I would rather disable the port, however to get things up and running I’ll give it a try. A possible solution from the Github project shows editing several files to make this work. A simple ack 8080 /var/snap/microk8s/current/args showed 4 locations which need to change:

/var/snap/microk8s/current/args/kube-proxy 1:–master=’http://127.0.0.1:8080’

/var/snap/microk8s/current/args/kube-apiserver 15:–insecure-port=8080

/var/snap/microk8s/current/args/kube-controller-manager 1:–master=’http://127.0.0.1:8080’

/var/snap/microk8s/current/args/kube-scheduler 1:–master=’http://127.0.0.1:8080’

I chose to use API_PORT=32432 for this test case. After running the following script with that adjustment I get the proper kubectl get nodes output. This one is obviously not a long term solution since microk8s is designed for a development flow, however it get me moving forward until I can get the other machines on-line next month.

#!/bin/bash
# define our new port number
API_PORT=32432

# update kube-apiserver args with the new port
# tell other services about the new port
sudo find /var/snap/microk8s/current/args -type f -exec sed -i "s/8080/$API_PORT/g" {} ';'

# create new, updated copies of our kubeconfig for kubelet and kubectl to use
mkdir -p ~/.kube && microk8s.config -l  | sed "s/:8080/:$API_PORT/" | sudo tee /var/snap/microk8s/current/kubelet.config > ~/.kube/microk8s.config

# tell kubelet about the new kubeconfig
sudo sed -i 's#${SNAP}/configs/kubelet.config#${SNAP_DATA}/kubelet.config#' /var/snap/microk8s/current/args/kubelet

# disable and enable the microk8s snap to restart all services
sudo snap disable microk8s && sudo snap enable microk8s