Introduce
In this article, I introduce how to use VMware Workstation Pro software on windows to create virtual machines (VMs). Then install kubernetes onto these VMs.
Requirements: Have a configuration server with 16GB RAM or more (8GB or 12GB is also possible but it will not be guaranteed) The server installs win10/win11/winserver and most importantly, the machine must have an internet connection (to download) package, docker image..) The architecture of the lab system will be as follows:
I plan to install the machines with the following information:
Virtual machine | Role | IP | RAM | CPU | HDD | Note |
---|---|---|---|---|---|---|
master1 | master | 192.168.10.11 (NAT) | 2GB | 2 cores | 30GB | Will install more haproxy |
worker1 | worker | 192.168.10.12 (NAT) | 4GB | 2 cores | 30GB | Will install more rancher |
worker2 | worker | 192.168.10.13 (NAT) | 4GB | 2 cores | 30GB + 30GB | Will install more nfs-server |
kubespray | installation server | 192.168.10 (NAT) | 2GB | 2 cores | 30GB |
Note: The above RAM/CPU configuration is an example with a 16GB RAM case, if you have more, you can increase it for comfort. Note that the configuration of k8s node is at least 2GB of RAM.
Basically, install VMware Workstation on your PC to create virtual machines. Create 3 virtual machines running Centos7 (master1, worker1, worker2) to install k8s, kubespray virtual machine to be the installation server. From this kubespray virtual machine, I will install k8s on the above 3 nodes.
On the PC will install mobaxterm (or puty or SSH-Client you are familiar with) to connect to k8s after installation.
Steps to take
I will show you how to install the kubernetes lab system in the main steps (assuming you already have a windows PC)
- Install VMware Workstation Pro on Windows PC + Configure network for vmware
- Install a new VM using Centos7 + configure basic parameters
- Clone the above VM into 04 VMs with names respectively: master1, worker1, worker2 and kubespray
- Update hostname, IP.. for new cloned VMs
- Configure the kubespray virtual machine to prepare for the installation of k8s
- Parameter configuration for k8s installation + installation using kubespray
Detailed instructions
Install VMware Workstation Pro
You refer to the link to download and install VMware Workstation Pro here . Basically, only next is done, then I don’t give further instructions.
Network Configuration for VMware Workstation Pro
This step is for the purpose of setting up the IP range I will use for virtual machines (VMs) later. To do this, open VMware Workstation Pro and go to edit ==> Virtual Network Editor ==> Select the network type as NAT :
Here, I guide you to use NAT, then the VMs will be given a private IP in the range that you set in the Subnet IP section. You can set up this range arbitrarily, here I recommend using the range 192.168.10.0 mask 255.255.255.0 (as shown).
Centos7 installation guide and parameter configuration
Install centos7 on a virtual machine (VM)
First you download the Centos7 installer here , remember to choose the right file ” CentOS-7-x86_64-Minimal-2009.iso ” for it to be lightweight!
After downloading the file to your computer, open VMware Workstation Pro to prepare to install a new VM. You go to File ==> New Virtual Machine.. ==> Typical ==> Next ==> Installer disc image file (iso): ==> Point to the centos iso file that you downloaded to your computer in the previous step ==> next
Continue to enter the name of the VM (the name displayed on VMworkstation Pro) and the place where you want to save this virtual machine ==> Next:
In the “Maximum disk size (GB)” section, select the size of 30GB, tick ” Split virtual disk into multiple files ==> Next.
Almost done, now it’s time to configure the resources for the virtual machine. Tick ” Poweron this virtual machine after creation ” and click Customize Hardware… :
Here are a few points to note:
- Memory: Choose 2048 (2GB)
- Processors: Select 1 processor * 2 cores. If your computer has a good chip, it can be increased accordingly.
- Network Adapter: Tick the checkbox ” NAT: Used to share the host’s IP address ”
Okie, now click Finish to start the installation. In this interface, press Enter to do it quickly without having to wait for tens of seconds:
In the first interface, select English language:
Next in this interface we will configure the time (datetime), installation partition (INSTALLATION DESTINATION) and network.
Select DATE & TIME and set the server time + set timezone to HCM ==> Press Done when done.
Continue to select ” INSTALLATION DESTINATION ” ==> Select the 30GB drive that we created ==> Done
Next is to configure Hostname and network. First enter hostname as centos7 ==> Apply. Next enable the Ethernet network (ens33) to make it green as shown:
Click on Configure… to configure the IP for it:
IP | Netmask | Gateway |
---|---|---|
192.168.10.20 | 255.255.255.0 | 192.168.10.2 |
The DNS I set is 2 DNS of google so that the VM can connect to the internet: 8.8.8.8, 8.8.4.4
The reason here I set the IP as 192.168.10.20 is to avoid the IPs I have planned for the nodes. Later, when I clone this virtual machine, I will correct the IP according to the plan.
After completing the above step, we click Begin Installation to begin the installation of Centos 7. Next we need to set the password for the root user by clicking on ROOT PASSWORD and entering the password twice.
Click on USER CREATION to create a super user named sysadmin:
Please note the password for this root and sysadmin user for future use!
When the installation is complete, there will be a message to reboot the virtual machine, click reboot :
After reboot we can login with the user/pass created above and check the IP of the virtual machine:
So it has been successfully assigned IP 192.168.10.20 already.
Next, we use SSH client software to connect to it, making it easier to operate than directly on the console of VMware workstation.
Configuring parameters for virtual machines
First we configure the sysadmin user to have sudo privileges without a password. We edit the file /etc/sudoers and add the following line at the end of the file:
1 2 | [sysadmin@centos7 ~]$ sudo vi /etc/sudoers |
1 2 | sysadmin ALL=(ALL) NOPASSWD: ALL |
Then we need to check and disable swap on centos. Use the following command to check:
1 2 3 4 5 6 7 8 9 | [sysadmin@centos7 ~]$ free -h total used free shared buff/cache available Mem: 1.8G 234M 1.4G 9.6M 191M 1.4G Swap: 2.0G 0B 2.0G [sysadmin@centos7 ~]$ cat /etc/fstab |grep -v "^#" |grep -v "^$" /dev/mapper/centos-root / xfs defaults 0 0 UUID=6472fc80-1e29-406a-9864-20962b525d37 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 |
So the system is using swap, and has the mount in the fstab configuration.
To disable swap we do 2 things:
- Use the command disable swap:
1 2 3 4 5 6 7 | [sysadmin@centos7 ~]$ sudo swapoff -a [sysadmin@centos7 ~]$ free -h total used free shared buff/cache available Mem: 1.8G 236M 1.4G 9.6M 191M 1.4G Swap: 0B 0B 0B |
- Remove the line mount swap in the file /etc/fstab (if there is a line with swap, comment it with a “#” at the beginning of the line:
1 2 | [sysadmin@centos7 ~]$ sudo vi /etc/fstab |
1 2 | #/dev/mapper/centos-swap swap swap defaults 0 0 |
Here you download this repo to your computer to get the initial installation script files: https://github.com/rockman88v/kubernetes_basic_course.git
In the session02-Installation/scripts folder, you copy 2 files ” update-vm.sh ” and ” configure-vm.sh ” to the virtual machine in the /home/sysadmin directory (the root directory of the sysadmin user). Then assign execute permissions to these two script files and run the configure-vm.sh script:
1 2 3 4 5 6 7 8 9 10 11 | [sysadmin@centos7 ~]$ sudo chmod +x update-vm.sh [sysadmin@centos7 ~]$ sudo chmod +x configure-vm.sh [sysadmin@centos7 ~]$ ls -lrt total 8 -rwxrwxr-x. 1 sysadmin sysadmin 556 Sep 14 19:10 update-vm.sh -rwxrwxr-x. 1 sysadmin sysadmin 272 Sep 14 19:10 configure-vm.sh [sysadmin@centos7 ~]$ ./configure-vm.sh Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. net.ipv4.ip_forward = 1 |
Basically, you have installed and configured a virtual machine ready for the installation of k8s later. We will shutdown any virtual machine to clone it into virtual machines for installation.
Shutdown the virtual machine from the current ssh session:
1 2 | sudo poweroff |
Clone virtual machine
Go to VMware Workstation and select the virtual machine we just installed ==> Right-click and select Manage ==> Clone ==> Next ==> Next ==> Create a full clone:
First, we clone into the master1 virtual machine, we name it and choose the folder to save the virtual machine:
After completing, we select the new virtual machine to clone (master1) ==> Right-click ==> Setting and adjust RAM/CPU/HDD parameters as initial planning.
Repeat the step of cloning the virtual machine into worker1, worker2 and kubespray machines (note the adjustment of RAM/CPU/HDD parameters as in the initial planning).
As for the worker2 virtual machine, we will add it a new disk of 30GB capacity (later as an NFS server to install the storage class that will be used in the following lessons): Right-click the worker2 virtual machine ==> Manage ==> Add. .. ==> Hard Disk ==> SCSI ==> Create a new virtual disk ==> Set space to 30GB + tick split virtual disk into multiple files ==> Next ==> Finish ==> OK
At the end of the clone process, we have 04 virtual machines according to the design .
Update hostname, IP for new cloned VMs
After cloning the 4 virtual machines, we will turn on each virtual machine to reconfigure the correct hostname/IP according to planning (because of the full clone, all 4 virtual machines are being set with the same hostnam/IP).
For example with master1 we turn it on, and update the hostname/IP with the command below:
NOTE:
It should be done on the console of VMware Workstation because after running the VM’s IP will change to the correct planning. So if SSH from an SSH Client, it will lose connection after running the script
1 2 3 4 5 6 7 | [sysadmin@master1 ~]$ ./update-vm.sh master1 192.168.10.11 master1 [sysadmin@master1 ~]$ sudo systemctl restart network [sysadmin@master1 ~]$ ifconfig ens33 |grep inet inet 192.168.10.11 netmask 255.255.255.0 broadcast 192.168.10.255 inet6 fe80::9dcd:369b:47bd:f107 prefixlen 64 scopeid 0x20<link> |
So the hostname and IP have been updated.
Do the same with the rest of the virtual machines.
As for the worker2 virtual machine , we need one more step to mount a new disk for it (in the previous step we added a disk for it).
1 2 3 4 5 6 7 8 9 10 | [sysadmin@worker2 ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 30G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 29G 0 part ├─centos-root 253:0 0 27G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm sdb 8:16 0 30G 0 disk sr0 11:0 1 973M 0 rom |
So the new disk is at /dev/sdb . We mount the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | [sysadmin@worker2 ~]$ sudo mkfs.ext4 /dev/sdb mke2fs 1.42.9 (28-Dec-2013) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) y <output truncated> Writing superblocks and filesystem accounting information: done [sysadmin@worker2 ~]$ sudo mkdir /nfs-data [sysadmin@worker2 ~]$ sudo mount /dev/sdb /nfs-data [sysadmin@worker2 ~]$ df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 899M 0 899M 0% /dev tmpfs 910M 0 910M 0% /dev/shm tmpfs 910M 9.6M 901M 2% /run tmpfs 910M 0 910M 0% /sys/fs/cgroup /dev/mapper/centos-root 27G 1.5G 26G 6% / /dev/sda1 1014M 194M 821M 20% /boot tmpfs 182M 0 182M 0% /run/user/1000 /dev/sdb 30G 45M 29G 1% /nfs-data |
So the new disk has been mounted to /nfs-data. We need to configure more in /etc/fstab so that after reboot it will be mounted again. We add the following line to the file:
1 2 | /dev/sdb /nfs-data ext4 defaults 0 0 |
So here we have basically finished setting up 04 VMs with the correct configuration according to the original planning :
Virtual machine | Role | IP | RAM | CPU | HDD | Note |
---|---|---|---|---|---|---|
master1 | master | 192.168.10.11 (NAT) | 2GB | 2 cores | 30GB | Will install more haproxy |
worker1 | worker | 192.168.10.12 (NAT) | 4GB | 2 cores | 30GB | Will install more rancher |
worker2 | worker | 192.168.10.13 (NAT) | 4GB | 2 cores | 30GB + 30GB | Mounted to /nfs-data |
kubespray | installation server | 192.168.10 (NAT) | 2GB | 2 cores | 30GB |
In the next section, we will configure the kubespray VM to install the k8s cluster .