Recently I set up a private Kubernetes (k8s) cluster on my home GPU servers. Since the cluster is private, it is not exposed to the internet.
This means that the docker-registry for hosting the container images is also private within the cluster. The private registry is not so straightforward to set up, but we will discuss it below.
First, we need one or more machines for the cluster. One will be the main (master) of the cluster, and the rest will be joining as nodes. If you have only one machine, no worries - the machine hosting the master can also run as a node.
I'm running Ubuntu Server 20.04 - this is much easier to set up than the Ubuntu Desktop with GUI. In fact, the whole process takes less than an hour, and even the notorious Nvidia driver installation is a breeze since we don't need to deal with GUI and X Server. See the linked post for guide.
the kubeadm init step will output a command for nodes to join the cluster. You can wait until the registry is set up below to join to ensure the registry in on your main.
Kubernetes should auto-restart when host machine restarts. If not, check the status and possibly turn off the swap.
install Octant on your local (laptop) for dashboard
Generate service account kubeconfig for access: on the kubernetes master host machine, create a service account kubeconfig for your local machine, then copy the generated config file sa-conf to local, and update the local ~/.kube/config:
Install Prometheus and Grafana
How-tos
Push image to registry
To push images from local to the registry, you can:
on a k8s node: tag image with the clusterIP 10.96.10.96:5000 and push directly
outside of node: you need to port-forward the service directly and push to 0.0.0.0:5000
build your image with the either clusterIP or localhost tag and push:
# on master node
sudo bash bin/make_kube_config.sh sa default
# copy this content for ~/.kube/config below
cat /tmp/kube/sa-conf
# on user local
# backup your old config
cp ~/.kube/config ~/.kube/config_backup
# paste the content above into ~/.kube/config
nano ~/.kube/config
# check nodes
k get nodes
k create namespace monitoring
helm install prometheus stable/prometheus-operator -n monitoring
# grafana
kpf svc/prometheus-grafana 3000:80 -n monitoring
# default creds: admin:prom-operator
# the choose some predefined k8s cluster dashboards
# registry for direct docker push
kpf service/private-docker-registry 5000 -n docker