Skip to main content
Blog

Your own private Kubernetes cluster at home

By 19 februari 2019No Comments

So, you decided to setup your own Kubernetes cluster on some old pc or Raspberry Pi you’ve just got laying around. Great! Your own personal private Kubernetes cluster just for you to experiment with, just because you don’t want to use Minikube.

The basics

The first thing you do is search the internet for the documentation on how to install it. For me, it would be installed on an Ubuntu server, so I came out on https://kubernetes.io/docs/setup/independent/install-kubeadm/

First thing to do, is install Kubernetes.

#turn swap off
swapoff -a
#initialize the kubernetes master
kubeadm init
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

You will see instructions from kubeadm on how to join other nodes to the cluster. If you want to run containers on your master as well (as it might be your only node), just run

kubectl taint nodes --all node-role.kubernetes.io/master-

Weave and the Dashboard

Next, you apply Weave and the dashboard:

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"
export kubever=$(kubectl version | base64 | tr -d '\n')
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"
sudo cp /etc/kubernetes/admin.conf .
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

If you want to log in to the cluster with the admin user, you can find the token by using the command:

kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

All this can be found online relatively easily. Nothing special so far.

Ingress

Now to create the ingress controller (which is easy in the cloud or Minikube). I went to the Minikube repo https://github.com/kubernetes/minikube/tree/master/deploy/addons/ingress and applied the Ingress files with

kubectl apply -f <file-name>

Heapster

Now for something with a little more cool factor. You’ve heard of Horizontal Pod Auto-scaling: scaling your pods based on metrics served from the cluster. In the cloud, this would be installed by default. But not on our cloud. So what now?
What I did, was use the files in the Minikube repo https://github.com/kubernetes/minikube/tree/master/deploy/addons/heapster to install Heapster, Influx and Grafana with the apply command from above.

So Heapster is installed, but we can’t see any graphs in the dashboard. What is going on? As we can see from the logging of the Heapster pod, it cannot scrap the cluster. It hasn’t got the right roles and rights.

kubectl create clusterrole nodestatscreator --verb=create --namespace=default --resource=nodes/stats
kubectl create clusterrolebinding nodestatscreatorbinding --clusterrole=nodestatscreator --serviceaccount=kube-system:default

kubectl create clusterrole nodereader --verb=get --verb=list --verb=watch --resource=nodes
kubectl create clusterrolebinding nodereaderbing --clusterrole=nodereader --serviceaccount=kube-system:default

kubectl create clusterrole podreader --verb=get --verb=list --verb=watch --resource=pods
kubectl create clusterrolebinding podreaderbinding --clusterrole=podreader --serviceaccount=kube-system:default

kubectl create clusterrole namespacereader --verb=get --verb=list --verb=watch --resource=namespaces
kubectl create clusterrolebinding namespacereaderbinding --clusterrole=namespacereader --serviceaccount=kube-system:default

Now, delete your pod and let the Replicaset create a new one for you. Let the pod restart and then refresh your dashboard. It should now show you some graphs with CPU and memory stats on them. This means that the auto-scaler should work.

 

Happy deploying.