Utilize Ansible and Vagrant to rapidly deploy a Kubernetes cluster in a Test environment.
The Kubernetes cluster we will create is shown in the diagram above. It consists of three vagrant nodes kube nodes
- k8smaster
- k8snode1
- k8snode2
These servers are located in different subnets compared to your development machine ansible node
- devbuild
Follow these steps to implement the setup:
Provision VMs
Login into your ansible node
vagrant up
vagrant ssh devbuildChange the root password for ansible node and switch to root
sudo passwd
su - Update the package manager and install Git
apt update
apt install git -yDownload this repository to devbuild machine, access ansible and bash scripts
cd /
git clone https://github.com/odennav/kubeadm-ansible-ubuntu.git
cd kubeadm-ansible-ubuntuGenerate SSH public/private key pair
ssh-keygen -t rsa -b 4096Once the RSA key-pair is generated, manually copy the public key id_rsa.pub to the /root/.ssh/authorized_keys file in all kube nodes.
Install Ansible in devbuild
sudo apt install -y software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install -y ansibleThe bootstrap and k8s folders in this repository contain the Ansible scripts necessary to set up your servers with the required packages and applications.
All nodes will be bootstrapped using Ansible.
Bootstrap the master node
cd kubeadm-ansible-ubuntu/bootstrap/
ansible-playbook bootstrap.yml --limit k8s_masterBootstrap the worker nodes
ansible-playbook bootstrap.yml --limit k8s_nodeOnce the bootstrap is complete, you can log in as odennav-admin.
Confirm SSH access to master node
ssh odennav-admin@192.168.50.2Confirm SSH access to 1st worker node
ssh odennav-admin@192.168.50.3To return to devbuild, type exit and press Enter or use Ctrl+D
Confirm SSH access to 2nd worker node
ssh odennav-admin@192.168.50.4Your kube nodes are now ready to have a Kubernetes cluster installed on them.
Execute playbooks in this particular order:
cd ../kubeadm
ansible-playbook k8s.yml --limit k8s_master
ansible-playbook k8s.yml --limit k8s_nodeCheck status of your nodes
kubectl get nodesYour Kubernetes cluster is ready.
Enjoy!
