Create a Kubernetes Docker Cluster on Ubuntu Server

Channel:
Subscribers:
14,400
Published on ● Video Link: https://www.youtube.com/watch?v=8q9uPjDF59Q



Duration: 7:17
348 views
12


#Docker #Kubernetes #Ubuntu

Full steps can be found at https://i12bretro.github.io/tutorials/0421.html

Preparing the VMs
    Log into a freshly installed Ubuntu VM
   01. Run the following commands
         # set the hostname
         sudo hostnamectl set-hostname kubernetes
         # update hosts file
         sudo nano /etc/hosts
   02. Update the 127.0.01 to the new hostname, kubernetes
   03. Press CTRL+O, Enter, CTRL+X to write the changes to hosts
   04. Continue with the following commands
         # disable the firewall
         sudo ufw disable
         # disable the swap file
         sudo swapoff -a
         # disable swap partition
         sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
         sudo echo "vm.swappiness=0" | sudo tee --append /etc/sysctl.conf
         # update sysctl networking
         cat ≪ net.bridge.bridge-nf-call-ip6tables = 1
         net.bridge.bridge-nf-call-iptables = 1
         EOF
         sudo sysctl --system
         # apply the changes
         sudo sysctl -p
 
Installing Docker
    Continue with the following commands in terminal     # install prerequisites
    sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y
    # add docker gpg key
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    # add docker software repository
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    # install docker
    sudo apt install docker-ce docker-compose containerd.io -y
    # enable and start docker service
    sudo systemctl enable docker && sudo systemctl start docker
    # add the current user to the docker group
    sudo usermod -aG docker $USER
    # reauthenticate for the new group membership to take effect
    su - $USER     
 
Installing Kubernetes
    Continue with the following commands in terminal     # add kubernetes gpg key
    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
    # add the kubernetes software repo
    echo 'deb http://apt.kubernetes.io/ kubernetes-xenial main' | sudo tee /etc/apt/sources.list.d/kubernetes.list
    # update software repositories
    sudo apt update
    # install kubernetes
    sudo apt install kubelet kubeadm kubectl -y
    # shutdown the VM
    sudo shutdown now     
 
Cloning the VirtualBox VM
    In VirtualBox Manager, right click on the Kubernetes VM ≫ Clone...
   01. Name the cloned VM Docker1 ≫ Click Next
   02. Make sure Full Clone is selected ≫ Click Clone
   03. In VirtualBox Manager, right click on the Ubuntu VM again ≫ Clone...
   04. Name the cloned VM Docker2 ≫ Click Next
   05. Make sure Full Clone is selected ≫ Click Clone
   06. Right click the Kubernetes VM ≫ Start ≫ Normal Start
   07. Right click the Docker1 VM ≫ Start ≫ Normal Start
   08. Once the VM boots, log in and run the following commands
         # set the hostname
         sudo hostnamectl set-hostname docker1
         # update hosts file
         sudo nano /etc/hosts
   09. Update the 127.0.01 to the new hostname, docker1
   10. Press CTRL+O, Enter, CTRL+X to write the changes to hosts
   11. Reboot the VM with the following command
         sudo reboot now
   12. Back in VirtualBox Manager, right click the Docker2 VM ≫ Start ≫ Normal Start
   13. Once the VM boots, log in and run the following commands
         # set the hostname
         sudo hostnamectl set-hostname docker2
         # update hosts file
         sudo nano /etc/hosts
   14. Update the 127.0.01 to the new hostname, docker2
   15. Press CTRL+O, Enter, CTRL+X to write the changes to hosts
   16. Reboot the VM with the following command
         sudo reboot now
   17. At this point we have 3 Ubuntu VMs (kubernetes, docker1, docker2) running with swap disabled and docker and kubernetes installed
   18. All 3 VMs will need static IP addresses, I prefer to create static DHCP leases on my router for a single point of configuration, but the VM IP addresses can be set with the following command if needed
         sudo nano /etc/netplan/01-installer-config.yaml
   19. Set DHCP4 = no and update the IP address, gateway and nameservers
         dhcp4: no
         addresses: [192.168.100.100/24]
         gateway4: 192.168.100.1
         nameservers:
         addresses: [192.168.100.1,8.8.8.8]
 
Configuring the Kubernetes Cluster
Follow the steps below only on the kubernetes VM
 
    Log into the kubernetes VM and run the following commands in terminal     # initialize the cluster, copy the kubeadm join command for use later when joining the docker hosts to the cluster


....Full steps can be found on GitHub [link at the top]


### Connect with me and others ###
★ Discord: https://discord.com/invite/EzenvmSHW8
★ Reddit: https://reddit.com/r/i12bretro
★ Twitter: https://twitter.com/i12bretro







Tags:
Kubernetes Installation
Install Kubernetes On Ubuntu
Kubernetes Tutorial
Kubernetes
VirtualBox
Docker
Docker Made Easy
Install Guide
Home Lab
Containerization
Orchestration
Self-Hosted
Virtual Machines
Ubuntu
Ubuntu Server
Cluster
SSH
Command Line
CLI
How To
Tutorial
i12bretro