This contains the working code to setup kubernetes using anisble and vagrant.
adheres to offical documentation : https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/
- Vagrant should be installed on your machine. Installation binaries can be found here.
- Oracle VirtualBox can be used as a Vagrant provider or make use of similar providers as described in Vagrant's official documentation.
- Ansible should be installed in your machine. Refer to the Ansible installation guide for platform specific installation.
- Clone repo
git clone https://github.com/naveenrajm7/k8s-setup.git
- Execute vagrant inside folder
cd k8s-setup
vagrant up
- Access master and use kubernetes
$ ## Accessing master
$ vagrant ssh k8s-master
vagrant@k8s-master:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 14m v1.23.3
node-1 Ready <none> 9m37s v1.23.3
node-2 Ready <none> 5m19s v1.23.3
vagrant@k8s-master:~$ kubectl create ns my-ns
namespace/my-ns created
-
Copy ~/.kube/config to host machine
https://www.alexkras.com/how-to-copy-one-file-from-vagrant-virtual-machine-to-local-host/ -
Make sure the ip address of vagrant VMs are reachable https://www.vagrantup.com/docs/networking/private_network.html
-
Make sure you are not in a VPN , as this will make VM IPs unreachable.