how to install kubernetes

Introduction:

Kubernetes is a powerful container orchestration platform that can help you manage your containerized applications with ease. In this guide, we'll show you how to set up a Kubernetes cluster on Ubuntu, step-by-step.

Prerequisites:

Before we get started, you'll need to make sure you have the following prerequisites:
  • Ubuntu 18.04 or later installed on all nodes
  • SSH access to all nodes with a sudo-enabled user
  • Kubernetes CLI tool (kubectl) installed on your local machine

Step 1: Install Docker

Kubernetes relies on Docker to manage containers. To install Docker on Ubuntu, run the following commands:
  • sudo apt update
  • sudo apt install docker.io
Once Docker is installed, start and enable it to run on boot with the following commands:
  • sudo systemctl start docker
  • sudo systemctl enable docker

Step 2: Install Kubernetes 

To install Kubernetes, we'll use the kubeadm tool. This tool allows us to easily set up a cluster and manage nodes. 

First, add the Kubernetes apt repository key and repository by running the following commands:

  1. curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
  2. sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

Next, install the kubeadm, kubelet, and kubectl packages by running the following commands:

  • sudo apt update
  • sudo apt install -y kubeadm kubelet kubectl

Step 3: Initialize the Kubernetes Master Node


Now that we have Docker and Kubernetes installed, we can initialize the Kubernetes master node. Run the following command to initialize the cluster:

  • sudo kubeadm init --pod-network-cidr=192.168.0.0/16

This command will initialize the Kubernetes master node and print out a kubeadm join command that you'll need to use later to join worker nodes to the cluster.

Make a note of this command, as you'll need it later.

Step 4: Configure kubectl on Your Local Machine


To manage your Kubernetes cluster from your local machine, you'll need to configure kubectl. To do this, copy the kubeconfig file from the master node to your local machine by running the following commands:
  • mkdir -p $HOME/.kube
  • sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  • sudo chown $(id -u):$(id -g) $HOME/.kube/config

Step 5: Install a Pod Network Addon


In order for your pods to communicate with each other, you'll need to install a pod network addon. We'll be using the Calico network plugin for this guide.

To install Calico, run the following command:

  1. kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml

Step 6: Join Worker Nodes to the Cluster


Now that the master node and pod network are set up, we can join worker nodes to the cluster.

On each worker node, run the kubeadm join command that was printed out in Step 3. This will join the worker node to the Kubernetes cluster.

By following this step-by-step guide, you can easily set up a Kubernetes cluster on Ubuntu and start deploying and managing your containerized applications with ease. Remember to keep your cluster up-to-date with security patches and monitor it regularly to ensure that it's running smoothly.