In the past I broke my K3s homelab more than few times. To set up K3s cluster again it was not complicated. I want to automate process of set up my cluster. Pararerly I started prepare to CKA exam. I done some reserach, and I find tool to set up cluster for me. This tool was kubespray(1). You may ask what is Kubespray. Kubespray is an open-source application developed to automate Kubernetes installation and configuration processes. It uses Ansible to perform instalation regardless of the infrastructure(2).
Kubespray support 14 Linux distributions(1).
It support core components like: kubernetes, etcd, docker, containerd, cri-0. For Network Plugins it support 8 plugins, for example support calico, cilium and flannel. It can install aplication like helm, cert-manager, argocd, ingress-nginx and metallb. Kubespray also has plugins for AWS, Azure, GCP and for local installation.
Stage 1. Preparation
To guarante success, for instalation process current users need to be added in sudoers file to not ask for password.

Add user to group to allow execute any command. It is important to reverse this set up after installation.
sidor ALL=(ALL) NOPASSWD:ALL
For better file management I create new folder for itmes from Github Kubespray repository. I set python venv to have area when requirements file will be installed.


Install apps from app list in file 'requirements.txt' with --ignore-installwed flag.
I clone Kubespray GitHub repository.

I declare IP adresse of my Ubuntu Servers in my local network. All servers had set SSH connection, by SSH-COPY-ID.
declare -a IPS=(10.0.0.4 10.0.0.5 10.0.0.6) 
In file listed below set select what core elements, apps and addons I want to be installed in my Homelab cluster.
cp -rfp inventory/sample inventory/sidor

- addons file

- cluster file
At first attempt, I failed. I thought, that only uninstall K3s will works. I was wrong.



Even set up was successfull, in final step, I copy config and add rights to this config.

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config



DOCS:
1. https://github.com/kubernetes-sigs/kubespray
2. https://faun.pub/guide-to-efficient-kubernetes-cluster-setup-with-kubespray-8a29c58b13a2
PS.













