How to Install Kubernetes Cluster on Ubuntu 24.04 | Step-by-Step Guide

Поділитися
Вставка
  • Опубліковано 8 жов 2024
  • In this tutorial, I will walk you through the process of installing a Kubernetes cluster on Ubuntu 24.04 using Kubeadm. We will cover each step required to get your cluster up and running, from setting hostnames to testing the deployment. Whether you're new to Kubernetes or looking to refine your setup, this guide is for you!
    In this video, you will learn:
    1) Set Hostname & Update Hosts File
    Configure the master and worker nodes' hostnames and update the hosts file for network communication.
    sudo hostnamectl set-hostname "k8s-control-node" // Master Node
    sudo hostnamectl set-hostname "k8s-worker01-node" // Worker Node 1
    sudo hostnamectl set-hostname "k8s-worker02-node" // Worker Node 2
    add the following lines to /etc/hosts file on each node
    192.168.1.56 k8s-control-node
    192.168.1.57 k8s-worker01-node
    192.168.1.58 k8s-worker02-node
    2) Disable Swap & Load Kernel Modules
    Disable swap memory and configure kernel modules like overlay and br_netfilter for Kubernetes.
    sudo swapoff -a && sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
    sudo modprobe overlay && sudo modprobe br_netfilter
    Create a file with following content
    sudo vi /etc/modules-load.d/k8s.conf
    overlay
    br_netfilter
    Next, add the kernel parameters like IP forwarding. Create a file and load the parameters using sysctl command,
    sudo vi /etc/sysctl.d/kubernetes.conf
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    net.ipv4.ip_forward = 1
    To load the above kernel parameters, run
    sudo sysctl --system
    3) Install Containerd
    Install and configure containerd with SystemdCgroup to manage container runtime.
    sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
    sudo curl -fsSL download.docke... | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/containerd.gpg
    sudo add-apt-repository "deb [arch=amd64] download.docke... $(lsb_release -cs) stable"
    sudo apt update && sudo apt install containerd.io -y
    containerd config default | sudo tee /etc/containerd/config.toml
    sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
    4) Add Kubernetes Package Repository
    Download and configure the Kubernetes package repository for Ubuntu 24.04.
    curl -fsSL pkgs.k8s.io/co... | sudo gpg --dearmor -o /etc/apt/keyrings/k8s.gpg
    echo 'deb [signed-by=/etc/apt/keyrings/k8s.gpg] pkgs.k8s.io/co... /' | sudo tee /etc/apt/sources.list.d/k8s.list
    5) Install Kubernetes Components
    Install Kubeadm, Kubelet, and Kubectl on all nodes to manage your Kubernetes cluster.
    sudo apt update
    sudo apt install kubelet kubeadm kubectl -y
    6) Initialize the Kubernetes Cluster
    Initialize the control plane node using Kubeadm.
    sudo kubeadm init --control-plane-endpoint=k8s-control-node
    On the master node, run following set of commands.
    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
    7) Join Worker Nodes
    Add worker nodes to your Kubernetes cluster using the token generated during initialization.
    sudo kubeadm join k8s-master-noble:6443 --token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    Now head back to the master node and run kubectl get nodes command to verify the status of worker nodes.
    kubectl get nodes
    8) Install Calico Network Plugin
    kubectl create -f raw.githubuser...
    After the successful installation of calico, nodes status will change to Ready in a minute or two.
    kubectl get pods -n kube-system
    kubectl get nodes
    9) Test Kubernetes Installation
    Create and expose an NGINX deployment to verify the setup.
    kubectl create ns demo-app
    kubectl create deployment nginx-app --image nginx --replicas 2 --namespace demo-app
    kubectl get deployment -n demo-app
    kubectl get pods -n demo-app
    kubectl expose deployment nginx-app -n demo-app --type NodePort --port 80
    kubectl get svc -n demo-app
    Now try to access your application using nodeport
    curl Any-worker-IP:30336
    By the end of this tutorial, you’ll have a fully functioning Kubernetes cluster with networking and a test deployment.
    📌 Commands and configurations mentioned in the video are included step-by-step. Make sure to follow along!
    🔔 Don’t forget to like, subscribe, and hit the bell icon to stay updated with more Linux and Kubernetes tutorials!
    #Kubernetes #Ubuntu24 #Kubeadm #Containerd #Linux #Calico #K8s

КОМЕНТАРІ • 2

  • @Fayaz-Rehman
    @Fayaz-Rehman 8 днів тому +1

    Great - Thank you - This is the power of bash scripting. I have a question: Are you using three nodes from kvm or bare metal hypervisor ? Also what if I want to install kubernetes 1.28 - will these scripts work for older versions. While switching off swap - the swap file also needs to be deleted to clear some space. Not sure if I can install everything as "root" user.

    • @linuxtechi9979
      @linuxtechi9979  8 днів тому

      I have used Virtual Box VMs in the demo. Yes, you can use the same steps and instructions for K8s 1.28, make sure you specify k8s version 1.28 while configuring APT repository