kubernetes-the-hard-way/docs/02-compute-resources.md

100 lines
3.6 KiB
Markdown
Raw Normal View History

2017-08-29 00:19:25 +03:00
# Provisioning Compute Resources
2019-03-20 07:34:49 +03:00
Note: You must have VirtualBox and Vagrant configured at this point
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
Download this github repository and cd into the vagrant folder
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
`github clone https://github.com/mmumshad/kubernetes-the-hard-way.git`
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
CD into vagrant directory
2017-08-29 00:19:25 +03:00
2019-03-20 08:21:04 +03:00
`cd kubernetes-the-hard-way\vagrant`
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
Run Vagrant up
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
`vagrant up`
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
This does the below:
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
- Deploys 5 VMs - 2 Master, 2 Worker and 1 Loadbalancer with the name 'kubernetes-ha-* '
> This is the default settings. This can be changed at the top of the Vagrant file
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
- Set's IP addresses in the range 192.168.5
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
| VM | VM Name | Purpose | IP | Forwarded Port |
| ------------ | ---------------------- |:-------------:| ------------:| ----------------:|
| master-1 | kubernetes-ha-master-1 | Master | 192.168.5.11 | 2711 |
| master-1 | kubernetes-ha-master-2 | Master | 192.168.5.12 | 2712 |
| worker-1 | kubernetes-ha-worker-1 | Worker | 192.168.5.21 | 2730 |
| worker-2 | kubernetes-ha-worker-2 | Worker | 192.168.5.22 | 2721 |
| loadbalancer | kubernetes-ha-lb | LoadBalancer | 192.168.5.30 | 2722 |
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
> These are the default settings. These can be changed in the Vagrant file
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
- Add's a DNS entry to each of the nodes to access internet
> DNS: 8.8.8.8
2017-08-29 00:19:25 +03:00
2019-03-25 13:13:46 +03:00
- Install's Docker on Worker nodes
2019-03-20 07:34:49 +03:00
- Runs the below command on all nodes to allow for network forwarding in IP Tables.
This is required for kubernetes networking to function correctly.
> sysctl net.bridge.bridge-nf-call-iptables=1
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
## SSH to the nodes
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
There are two ways to SSH into the nodes:
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
### 1. SSH using Vagrant
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
From the directory you ran the `vagrant up` command, run `vagrant ssh <vm>` for example `vagrant ssh master-1`.
> Note: Use VM field from the above table and not the vm name itself.
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
### 2. SSH Using SSH Client Tools
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
Use your favourite SSH Terminal tool (putty).
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
Use the above IP addresses. Username and password based SSH is disabled by default.
Vagrant generates a private key for each of these VMs. It is placed under the .vagrant folder (in the directory you ran the `vagrant up` command from) at the below path for each VM:
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
**Private Key Path:** `.vagrant/machines/<machine name>/virtualbox/private_key`
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
**Username:** `vagrant`
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
## Verify Environment
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
- Ensure all VMs are up
- Ensure VMs are assigned the above IP addresses
- Ensure you can SSH into these VMs using the IP and private keys
- Ensure the VMs can ping each other
- Ensure the master and worker nodes have Docker installed on them. Version: 18.06
> command `sudo docker version`
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
## Troubleshooting Tips
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
If any of the VMs failed to provision, or is not configured correct, delete the vm using the command:
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
`vagrant destroy <vm>`
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
Then reprovision. Only the missing VMs will be re-provisioned
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
`vagrant up`
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
Sometimes the delete does not delete the folder created for the vm and throws the below error.
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
VirtualBox error:
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
VBoxManage.exe: error: Could not rename the directory 'D:\VirtualBox VMs\ubuntu-bionic-18.04-cloudimg-20190122_1552891552601_76806' to 'D:\VirtualBox VMs\kubernetes-ha-worker-2' to save the settings file (VERR_ALREADY_EXISTS)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component SessionMachine, interface IMachine, callee IUnknown
VBoxManage.exe: error: Context: "SaveSettings()" at line 3105 of file VBoxManageModifyVM.cpp
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
In such cases delete the VM, then delete teh VM folder and then re-provision
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
`vagrant destroy <vm>`
2017-08-29 00:19:25 +03:00
2019-03-20 07:34:49 +03:00
`rmdir "<path-to-vm-folder>\kubernetes-ha-worker-2"`
`vagrant up`