Kubernetes Cluster Setup: Step-by-Step Process

NahidNahid
3 min read

Prerequisite:

  • One master (Control Plane) Node

  • Two or more servers for worker Node

  • 2 GB or more of RAM per machine

  • 2 CPUs or more for control plane machines

  • Full network connectivity between all machines in the cluster

  • Unique hostname, MAC address, and product_uuid for every node

  • Certain ports are open on your machines (if your server is new, the required ports are already open)

Server Setup:

First two or more servers will be required where one will be master node (control plane) and the rest will be worker nodes. Shown here with Ubuntu 22.04 LTS. So you must have Ubuntu 22.04 LTS installed on your system.

  • After creating three servers or nodes. Need to change or update the MAC address, product_uuid and hostname for every node including Master Node.

  • Also, we need to check if the available port is free or open for the cluster

  • Then permanently disable swap space on Master node. using this command:

      vi /ete/fstab
    
      #/swap.img      none    swap    sw      0       0
    

    After open the bash editor, then comment out or Add # before /swap.img

    Then forwarding IPv4 and letting iptables see bridged traffic:

      cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
      overlay
      br_netfilter
      EOF
    
      sudo modprobe overlay
      sudo modprobe br_netfilter
    

    Then install some dependencies file for adding the repositories:

      apt-get update
      sudo apt-get install apt-transport-https ca-certificates curl gpg
    

    Install CRI-O on Server:

    Before installing CRI-O, we need to install some dependency packages:

  •     curl -fsSL https://pkgs.k8s.io/addons:/cri-o:/prerelease:/main/deb/Release.key |
            gpg --dearmor -o /etc/apt/keyrings/cri-o-apt-keyring.gpg
    
        echo "deb [signed-by=/etc/apt/keyrings/cri-o-apt-keyring.gpg] https://pkgs.k8s.io/addons:/cri-o:/prerelease:/main/deb/ /" |
            tee /etc/apt/sources.list.d/cri-o.list
    

    Then update repository and install cri-o

  •     apt-get update
        apt-get install socat
        apt-get install cri-o
    

    After installing cri-o, we need to start and enable crio.service

      systemctl enable crio.service
      systemctl start crio.service
      systemctl status crio.service
    

    Add the Kubernetes repository:

      curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key |
          gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
    
      echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /" |
          tee /etc/apt/sources.list.d/kubernetes.list
    

    Installing process of Kubernetes:

    Now we have to install kubeadm, kubelet and kubectl, using below command:

      apt-get update
      sudo apt-get install kubelet kubeadm kubectl
      sudo apt-mark hold kubelet kubeadm kubectl
    

    Initialize Kubernetes Cluster:

    To initialize cluster, we have to run below command on master-node:

      kubeadm init
    

    Once the initialization is complete, some instructions will appear, which will help connect the worker nodes to the master node. This will contain a command to be run on the worker nodes.

    Create Cluster Join Token: (Control Plane)

      kubeadm token create --print-join-command
    

    You can generate a token by running this command. Through this token you can connect the worker nodes with the master node, if you go to those worker nodes and apply the token, then the worker node will be connected with the master node.

    Configuration of kubectl:

    Now set the kubeconfig on master-node, using below command:

      mkdir -p $HOME/.kube
      sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
      sudo chown $(id -u):$(id -g) $HOME/.kube/config
    

    After the cluster set-up is completed, we have to set up the inter-cluster network system via CNI Plugin.

      kubectl apply -f https://reweave.azurewebsites.net/k8s/v1.31/net.yaml
    

    Verify the Cluster:

    Run the “kubectl get nodes” command on the master node to verify the cluster. You can see the status of the master and worker nodes.

    And this is how you can set up a Kubernetes Cluster.

0
Subscribe to my newsletter

Read articles from Nahid directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nahid
Nahid

I am Mozahidul Islam Nahid, an engineer driven by a passion for continuous learning and growth. With six years of diverse professional experience. Which includes one year as DevOps engineer and four and a half years as administration and procurement specialist. Now I am dedicated to advance my career in DevOps engineering and cloud engineering.I am particularly passionate about server management and ongoing maintenance of websites post-deployment and I aspire to be a crucial part of these essential tasks for any company . Thank you!