How to Install Kubernetes on Ubuntu 18.04
The Open-source platform Kubernetes allows declarative configuration and automation of containerized workloads and services. An ecosystem of great size and rapid growth resides there. Several Kubernetes tools, services, and support options are available. Kubernetes derives its name from Greek, meaning pilot or helmsman. As an abbreviation, K8S is derived from the eight letters that lie between the “K” and the “s”.
# sudo apt-get update
Run the following command to install Docker:
sudo apt-get install docker.io
Similarly, repeat the process on each server acting as a node.
Enter the following to check the installation.
# docker ––version
Step 2: Install Kubernetes
Docker should be enabled on both nodes
By entering the following, Docker will be launched at boot:
# sudo systemctl enable docker
Make sure Docker is running:
# sudo systemctl status docker
If Docker isn’t running, you need to start it:
# sudo systemctl start docker
Then repeat the process on all the other nodes.
Step 3: Add Kubernetes Signing Key
You can get the Kubernetes signing key by running the following command:
# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
You can install curl if you receive an error that it is not installed by following step:
# sudo apt-get install curl
Install the signing keys by repeating the previous command. Perform the procedure on every server node.
Step 4: Add Xenial Kubernetes Repository on both the nodes
Kubernetes is not included in the default repositories. To add them, enter the following:
# sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
Repeat on each server node.
Step 5: Install Kubeadm
Install Kubernetes tools on both nodes through the following command:
# sudo apt-get install kubeadm kubelet kubectl
# sudo apt-mark hold kubeadm kubelet kubectl
Verify the installation with:
kubeadm version
Repeat for each server node.
Step 6: Begin Kubernetes Deployment
Disable the swap memory on each server
# sudo swapoff –a
Give Unique hostnames to each node(Master)
# sudo hostnamectl set-hostname master-node
On the worker node,
# sudo hostnamectl set-hostname worker01
Use this process to set hostname for eack node.
Initialize Kubernetes on the master node
On the master server node enter the following:
# sudo kubeadm init --pod-network-cidr=10.244.0.0/16
The process will take a minute. Once it finishes, kubeadm join message will display at the end. Make a note of the whole entry. This will be used to join the worker nodes to the cluster.
Enter the following to create a directory for the cluster:
# kubernetes-master:~$ mkdir -p $HOME/.kube
# kubernetes-master:~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# kubernetes-master:~$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
Step 7: Deploy Pod Network
Enter the following:
# sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Verify all the thing.
# kubectl get pods --all-namespaces
As we mentioned before you can enter the kubeadm join command on each worker node to do it. For this switch to worker node and run the following
# kubeadm join --discovery-token abcdef.1234567890abcdef --discovery-token-ca-cert-hash sha256:1234..cdef 1.2.3.4:6443
Replace the alphanumeric codes with those from your master server. Repeat for each worker node on the cluster. Wait a few minutes; then you can check the status of the nodes.
On master server enter the following:
kubectl get nodes
Now you will see the worker node in the system that you joined to the cluster and you should now have Kubernetes installed on your Ubuntu 18.04 instance.
Thank you for reading.
IaaS, PaaS and SaaS in cloud computing
Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It provides a unified API for managing containers across multiple hosts.
Kubernetes can be installed on various versions of Ubuntu, but the recommended version is Ubuntu 20.04 LTS.
The prerequisites for installing Kubernetes on Ubuntu include a 64-bit CPU architecture, 2 GB of RAM or more, and at least 20 GB of free disk space.
There are several methods to install Kubernetes on Ubuntu, including using the snap package, kubeadm, and kubespray. The recommended method is to use kubeadm, which is a tool for bootstrapping a Kubernetes cluster.
To install kubeadm on Ubuntu, you need to add the Kubernetes repository to your system and install the kubeadm package using the following commands:
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubeadm