update ubuntu packages
Before installing kubectl on Ubuntu, we need to update all the packages on the Ubuntu system. To update, we need to use Ubuntu's “apt” utility within the “update” command as follows:
set up docker
The first prerequisite to properly install Kubernetes on Ubuntu is to install Docker. To install Docker, we use Ubuntu's “apt” utility within the installation command. The Docker package should be mentioned as “docker.io” followed by the “-y” option to force the “apt” utility to install Docker. Docker will be installed after some time and you can start using it after enabling it.
, sudo apart to install docker.io -y
To enable Docker on Ubuntu systems, we use the “systemctl” utility. Two separate commands with the keywords “enabled” and “status” are used to enable the Docker service and check its status after enabling it. The output of the status query displays that the Docker service is running fine.
, sudo systemctl Able postal worker
, sudo systemctl status docker
After enabling the Docker utility, you need to start using the same “systemctl” utility followed by the keyword “start” and the service name “docker”.
, sudo systemctl start docker
Before installing Kubernetes, it is necessary to install the “curl” utility in your system so that you can add the Kubernetes key to your system. The “snap” package is used to install the “curl” utility. The utility will be installed successfully.
After installation of the “curl” utility, we use it within the command followed by the “fssl” option to get the GPG key of Kubernetes from its official cloud repository. This command gets the signing key as shown in the output image:
, curl -FSSL https:,packages.cloud.google.com,apart,Doctor,apt-key.gpg , sudo Tea ,usr,share,key rings,Kubernetes.gpg
Now, to add the Kubernetes repository to the default repository of our system, we need to use the “echo” command followed by the “deb” directive. Make sure your other Ubuntu node has Docker installed and you need to execute the following instructions on other nodes for smooth communication:
, echo “Deb [arch=amd64 signed-by=/usr/share/keyrings/Kubernetes.gpg] http:,apt.kubernetes.io, Kubernetes-Xenial Men” , sudo Tea -A ,etc,apart,sources.list
A utility called kubeadm, or Kubernetes Administrator, assists with cluster initialization. Using community-sourced standards speeds up setup. The task bundle that launches a container on each node is called a kubelet. You can access the cluster through the command line with the program. Run the following instructions on each server node to install the Kubernetes installation tool via the “snap” utility, followed by the “-classic” keyword for each command:
, sudo snap to install Kubelet –Classic
, sudo snap to install kubectl –Classic
, sudo snap to install kubeadm –Classic
After successful installation of Kubernetes tools, we use the version instructions for each tool to view the installed version as follows:
$ kubeadm version
Now it's time to configure the installed tools of Kubernetes on our system. In this section, you can learn how to prepare a server for Kubernetes deployment. Execute the following commands on each Linux machine that you have used as a node. First things first, turn off swap storage. To perform this operation run the “swapoff” command with the “-a” option. The “swapoff” command must be followed by the “sed” command as follows:
, sudo exchange -A
, sudo sed -I ,, Change , S,,,,,,,,,#\1/g' /etc/fstab
It's time to load the module of “containerd”. To load those modules, we open the “containerd” configuration file using the GNU nano editor. This file is in the “etc” folder as per the following order:
, sudo nano ,etc,module-load.d,containerd.conf
Upon opening the configuration file, we load the “overlay” and “br_netfilter” modules by adding the following two keywords:
After mentioning the modules in the files, we have to use the “modprobe” directive after the module name to finally load them.
, sudo modprobe overlay
, sudo modprobe br_netfilter
It's time to configure Kubernetes' network using its configuration file located in the “etc” folder. The GNU Nano editor is used to open the file.
, sudo nano ,etc,sysctl.d,Kubernetes.conf
To enable networking we need to set the following shown variables for Kubernetes. This configuration sets up iptables for Kubernetes. Now, make sure to save the file before exiting.
Now, we reload the system services and configuration forever. The “sysctl” utility is used here with the “-system” option. You will see that the new configurations have been added and reloaded, i.e. displayed in the output.
After successfully loading the Kubernetes modules and reloading the services, we need to assign a unique name to each node in your Kubernetes network. For example, we want to set the current node as the master node of the Kubernetes network. Therefore, we try the “hostnamectl” utility in the command to set the hostname as “master-node”.
, sudo hostnamectl set-hostname master-node
The worker node is also set up using the same instructions with a different node name; This command needs to be executed on the worker server.
, sudo hostnamectl set-hostname umar
Open the host configuration files on each node within our Kubernetes network and add the IP addresses of each node within the file. You need to mention host names along with IP addresses to uniquely identify them.
The image shows the IP addresses and their hostnames in the host configuration file that is opened through the Nano editor.
Make sure you are on the master node now and open the kubelet configuration file through the nano editor.
, sudo nano ,etc,default,kubelet
Make sure to write the following shown line in the file to set the KUBELET_EXTRA_ARGS variable for Kubernetes on the master node.
Now, you need to reload the recently set configuration within your master node and worker nodes. The “systemctl” utility is used with the “daemon-reload” keyword. After providing the password, don't forget to restart the Kubernetes service.
, systemctl daemon-reload
Finally, your Kubernetes service has been successfully installed and configured. Make sure to reload the Docker service and also execute the specified commands on the worker nodes.