Setting up a private Kubernetes cluster
2020/06/20
Last updated
2020/06/20
Last updated
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.
Before installing kubernetes, setup the node machines as follows.
Note that k8s pod image pull cannot use FQDN for in-cluster registry (see link). Use a reserved clusterIP instead.
Reserved clusterIP for registry:
10.96.10.96
Our private registry will run on the main. When setting up the k8s main node:
append the following to /etc/docker/daemon.json
:
restart docker: sudo systemctl restart docker
follow the official NVIDIA GPU device plugin until the step to configure runtime
as explained in this comment, k8s still needs nvidia-container-runtime
; install it:
add the following /etc/docker/daemon.json as required by k8s
restart docker and test:
Installs a self-hosted private Kubernetes.
NOTE: I use the zsh kubectl shortcuts below, e.g.
k, kaf, keti
install Kubernetes with kubeadm. Then install a local-path volume provisioner, and the StorageClass shall be local-path
.
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 a private Docker registry from Helm Hub.
install the NVIDIA device plugin on your cluster:
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
:
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:
useful DNS debugging guide