Creating a single-node Kubernetes cluster on Linux. For developers that use Linux on their desktop.
Install Docker. On Debian, you may install the docker.io
package from Debian or docker-ce
from Docker.
Install kubeadm (https://kubernetes.io/docs/setup/independent/install-kubeadm/)
Initialize a cluster with kubeadm and give it a pod-network-cidr
and service-cidr
. We need this for kube-router
to work. Choose something that doesn't conflict with existing routes to your machine. At time of writing, 172.20.0.0/16
is available. Let's divide it up.
The pod network will get 172.20.0.0/17
. The service network will get 172.20.128.0/17
.
$ sudo kubeadm init --pod-network-cidr=172.20.0.0/17 --service-cidr=172.20.128.0/17
At the end it will tell you to run the following as a regular user.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Per the "Installing a pod network add-on" instructions at https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/
The preqreuisite for kube-router
is that we initialized our Kubernetes cluster with --pod-network-cidr
specified, which we've already done.
Run the command below to install kube-router
.
$ kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml
You will need to install MetalLB (https://metallb.universe.tf/) or a similar pod to get load balancers to work. This will do the job of provisioning load balancers. Follow the instructions on https://metallb.universe.tf/tutorial/layer2/
$ kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/metallb.yaml
Create a YML file with your configuration per the tutorial. Here it is with our network from above. We will use part of the network from the pod-network-cidr
here.
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: tmg-lbs
protocol: layer2
addresses:
- 172.20.120.1-172.20.127.255
Run kubectl apply -f
on that file.
By default, your cluster will not schedule pods on the master for security reasons. Run this to fix that.
kubectl taint nodes --all node-role.kubernetes.io/master-
In order to tear down the Kubernetes cluster entirely, one should make sure to clean up any leftover state.
The following commands are recommended to be run as root:
kubeadm reset # this will prompt you
systemctl stop kubelet
systemctl stop docker
rm -rf /var/lib/cni/
rm -rf /var/lib/kubelet/*
rm -rf /etc/cni/
ifconfig kube-bridge down
ifconfig docker0 down
brctl delbr kube-bridge # brctl comes with bridge-utils in Debian
systemctl start docker
While technically kubeadm reset
should be sufficient to tear down the cluster, there have been issues with getting clusters to work afterward. See kubernetes/kubernetes#39557