Scripts to install a kubernetes cluster in Vagrant
You need a bash
enviroment with SSH, either a Linux Distro, a Mac OSX or Windows 10 Bash (see below for Windows)
You need also VirtualBox, Vagrant and Ansible installed in your environment.
The kit is for Unix, so works out of the box in Linux and OSX, as follows.
cd servers/vbox
vagrant up
vagrant ssh-config >>~/.ssh/config
Run sudo vi /etc/hosts
and add the following line:
127.0.0.1 master node1 node2 node3
pip install ansible
cd ../../kubernetes
ansible-playbook site.yml
That is. Once done, vagrant ssh master
and start playing with Kubernetes
The kit work also on Windows 10. However since Windows is not a native Unix, the procedure is slightly more complex and involves the use of two shells, the native PowerShell and Windows Bash.
The main problem is on Windows, ansible
is not available as a Windows application. You need to install Windows 10 Bash to use Ansible. On the other side, both VirtualBox and Vagrant are native Windows applications and does not work with Windows Bash.
So the procedure on Windows 10 is the following.
First of course download Mosaico. Then install VirtualBox and Vagrant for Windows, and open a Windows shell (CMD or PowerShell).
cd servers\vbox
vagrant up
vagrant ssh-config >config
Note we started the VM with Vagrant for Windows and we saved the configuration in a local file.
You need to launch notepad as an administrator. Search notepad then right-click and run it as an Administrator. Then open the file c:\Windows\System32\Drivers\etc\hosts
and add the following line:
127.0.0.1 master node1 node2 node3
Remember to save it.
Now, ensure you have Windows Bash. Go in the Windows Store and install Ubuntu. Finally, open Windows bash, and do the following steps.
First install python
, pip
and ansible
:
sudo apt-get update
sudo apt-get install python-pip
sudo pip install ansible
Second, create a proper configuration file for ssh
(note we have to replace C:
with /mnt/c
)
mkdir $HOME/.ssh
cd Mosaico3/servers/vbox
sed -e 's!C:!/mnt/c!g' <config >>$HOME/.ssh/config
Finally you can provision with ansible
Kubernetes:
cd ../../kubernetes
ansible-playbook sites.yml
Vagrant exposes port 6443 and the certificate can be used with the master hostname (by default master
).
If you have installed kubectl you can retrieve the configuration with:
ssh master sudo cat /etc/kubernetes/admin.conf | sed -e 's/10.0.0.10/master/' >~/.kube/config
After this command check you can access the cluster with kubectl get nodes
. You should get:
$ kubectl get nodes
NAME STATUS AGE VERSION
master Ready 10m v1.10.3
node1 Ready 9m v1.10.3
node2 Ready 9m v1.10.3
node3 Ready 9m v1.10.3