How to Install Kubernetes on Ubuntu 20.04 (Focal Fossa) part 1

Ahamad Mohammad
4 min readAug 21, 2020

--

— -

This blog serves as complete guide from setting up virtual machine to set up of Kubernetes (from now on i refer it as k8s) . This blog has two parts , part 1 is configuring Virtual machines. Part 2 is installing & configuring Docker and Kubernetes. I have configured all in one Laptop as Host and used Virtual Box to set upk8s environment.
My laptop configuration
16GB RAM
256GB SSD
Windows 10 Pro
Intel core i7–4800MQ
Topology of Kubernetes Cluster:
We are going to create one Master node (Control plane) and two nodes.
VM Specifications:
Minimum of 2 GB RAM (for Master node you can use 4GB )
2 Core (2 vCPUs) (Minimum 2 cores are needed for k8s set up, otherwise k8s would not install)
25 GB Free Space

— -

Creating Virtual Machine
we are going to download Oracle virtual box and create a virtual machine and clone it.

Install Virtual Box
Download and Install Virtual Box from https://www.virtualbox.org/ . Installation is pretty simple, double click on executable and rest of the installation steps are self explanatory.

Create a VM using instructions mentioned in these links , virtualbox guest additions is a convenience package and its optional to install.
https://itsfoss.com/install-linux-in-virtualbox/
https://itsfoss.com/virtualbox-guest-additions-ubuntu/
Restart the VM once installation is complete
Network set up for Kubernetes:
By default Virtual Box VM have NAT network adapter turned on, we need to turnoff that adapter. Set up two adapters ,one Bridged Network and one Host Network .

Bridged network set up
click on Oracle Virtual Box VM Manager → VM →settings →Network and choose “Enable Network Adapter” and select “Bridged Adapter” and leave all defaults.

Host only Network set up
Click on Oracle Virtual Box VM Manager →File →Host Network Manager
choose radio button “ configure Adapter manually”
IPv4 Address 192.168.188.1
IPv4 Netmask 255.255.255.0
Do not define DHCP server in the DHCP tab,leave the default set up.

Enable Host only Adapter for the VM

Click Virtual Box VM Manager → VM →settings →Network
Click Adapter 2 and choose below options
Attached to : Host-Only Adapter
Name : Virtual Box Host-only Ethernet Adapter #2
Disable NAT adapter in VM:
Click Virtual Box VM Manager → VM →settings →Network
Click Adapter 1 and unselect “Enable Netwrok Adapter” (Make sure its NAT adapter)

Make static address changes permanent
Start the virtual Machine
Open terminal window
Edit netplan file “$sudo vi /etc/netplan/01-network-manager-all.yaml” add below lines ,pay attention indentation as YAML is sensitive to indentation.

renderer: NetworkManager
ethernets:
enp0s8:
dhcp4: no
addresses: [192.168.188.119/24]
gateway4: 0.0.0.0
nameservers:
addresses: [0.0.0.0,8.8.8.8]

run below command to try the changes made and apply them

$sudo netplan try
Do you want to keep these settings?
Press ENTER before the timeout to accept the new configuration

press Enter …
$sudo netplan apply
reboot the box
$reboot

clone virtual machines for node2 and node3
start cloned VM and run below steps to set host name and IP address.
once VM is started open terminal,run hostnamectl

$hostnamectl

if you need to change host name , use below command
$ sudo hostnamectl set-hostname xxxx

Edit netplan file “$sudo vi /etc/netplan/01-network-manager-all.yaml” and modify the IP address in my case i modified to 192.168.188.114 and 192.168.188.119
Edit /etc/hosts file and make entries for all hosts.Add the following entries in /etc/hosts files on each node,
192.168.188.111 ahamad-virtualbox1
192.168.188.114 ahamad-virtualbox4
192.168.188.119 ahamad-virtualbox9

reboot the box
$reboot

Configure SSH

Install open SSH server
$sudo apt-get install openssh-server

Generate Keys
$ssh-keygen

Copy Keys to other nodes
$ssh-copy-id ahamad@192.168.188.114

Verify the connection by connecting through SSH
$ssh ‘ahamad@192.168.188.114’
you will get terminal view to 192.168.188.114 .

$exit ( this will bring you back to your VM environment)
repeat the above two steps for all other nodes.
Kubernetes needs root privileges, configure SSH for root

$ sudo -i
Set the root password (password for the root user).
# passwd
Edit the SSH server configuration file.
# vi /etc/ssh/sshd_config
Add the following line to this file,usually you will see like like “#PermitRootLogin prohibit-password” you can add the line below this
PermitRootLogin yes

Restart the SSH server daemon.
# /etc/init.d/ssh stop
# /etc/init.d/ssh start

Generate keys

#ssh-keygen -t rsa
accept default location for rsa file. This will create a file /root/.ssh/id_rsa.pub.

Copy the public key to be able to login remotely via SSH as root
#ssh-copy-id -i /root/.ssh/id_rsa.pub 127.0.0.1

make the public key authorized
#cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

Verify whether you can log in as root
#ssh root@127.0.0.1

copy public key to rest of nodes
# ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.188.114
# ssh root@192.168.188.114
# ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.188.119
# ssh root@192.168.188.119

At the end of this step all nodes should be able to connect using SSH as root.

This concludes part 1 , in part 2 we will discuss installation of Docker and Kubernetes.

--

--