You could do that with Ansible, there's kubespray [0] from the official project to do that. You may want to read [1] starting with [2]. There's also k3s [0] and k0s [4]. I've written about my setup here [5] also if you are interested.
[0]: https://github.com/kubernetes-sigs/kubespray
[1]: https://www.tauceti.blog/
[2]: https://www.tauceti.blog/posts/kubernetes-the-not-so-hard-wa...
[3]: https://k3s.io/
[5]: https://vmarchaud.fr/deploying-kubernetes-the-hard-way/