This repo is an easy way to get a 3-Node Kubernetes cluster stood up using Vagrant, Ansible and Kubeadm.
A simple vagrant up
once pre-requisites are installed, will get you all the way to a fully running cluster and kubectl
ready to go.
Please get the following installed first:
- VirtualBox
# add /etc/apt.sources.list
deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian <mydist> contrib
# add keys && verify (after)
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
# update && install
sudo apt-get update
sudo apt-get install virtualbox-6.1
install
libarchive-tools
to get toolbsdtar
, which is required but not supported in Ubuntu 19+:sudo apt install -y libarchive-tools
.
In the rep folder, run: vagrant up
This will do the following:
- create the
k8s-control
ubuntu VM Node. - install docker, kubernetes, kubeadm and init the cluster in
k8s-control
- create each
worker-N
ubuntu VM Node. - install docker, kubernetes, kubeadm and join each worker to
k8s-control
Node.
Once it's all up, check for errors, then check with commands: vagrant status
and you should see:
Current machine states:
k8s-control running (virtualbox)
worker-1 running (virtualbox)
worker-2 running (virtualbox)
This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.
Jump into a node with: vagrant ssh k8s-control
or vagrant ssh node-1
Check your cluster:
vagrant@k8s-control:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-control Ready control-plane,master 87m v1.23.5
worker-1 Ready <none> 83m v1.23.5
worker-2 Ready <none> 80m v1.23.5
Access your cluster via kubectl
from the k8s-control
Node.
(TODO) - access the cluster from your host computer using the ~/.kube/config
file from k8s-control
.
if you see this error when you run: journalctl -xeu kubelet
64] "Docker Info" dockerInfo=&{ID:JECY:YHJK:J7PW:2LCZ:B64F:M6PQ:BBXC:ORXL:HNRW:UXKT:X4CO:LM4D Containers:0 ContainersRunning:0 ContainersPaused:0 ContainersStopped:0 Images:7 Driver:ov
led to run kubelet" err="failed to run Kubelet: misconfiguration: kubelet cgroup driver: \"systemd\" is different from docker cgroup driver: \"cgroupfs\""
tatus=1/FAILURE
it means you need /etc/docker/daemon.json
with this config in it:
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
then restart docker: systemctl restart docker