Site icon APPECODE

How to Set Up and Use Kubernetes on Linux

APPECODE - Cybersecurity While Travelling

APPECODE - Cybersecurity While Travelling

How To Set Up And Use Kubernetes On Linux

Introduction

Kubernetes (often abbreviated as K8s) is a powerful open-source platform designed to automate deploying, scaling, and managing containerized applications. This tutorial will guide you through setting up a single-node Kubernetes cluster on a Linux machine using kubeadm.

Step 1: Prerequisites

  • A Linux machine (Ubuntu 20.04 or newer is recommended)
  • sudo privileges
  • At least 2 CPUs and 2 GB of RAM
  • Basic knowledge of the command line

Step 2: Disable Swap

Kubernetes requires swap to be disabled. You can do this with the following command:

sudo swapoff -a

To disable it permanently, comment out the swap line in /etc/fstab.

Step 3: Install Docker

Kubernetes needs a container runtime. Docker is the most common choice:

sudo apt update
sudo apt install docker.io -y
sudo systemctl enable docker
sudo systemctl start docker

Step 4: Install Kubernetes Tools

Install kubeadm, kubelet, and kubectl:

sudo apt update
sudo apt install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

Step 5: Initialize the Cluster

Run the following command to initialize Kubernetes:

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

After initialization, follow the instructions printed on-screen to set up kubectl access for your user account:

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

Step 6: Install a Pod Network

You need a network plugin to allow communication between pods. Apply the Calico plugin:

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

Step 7: Verify the Cluster

Check the status of the nodes and pods:

kubectl get nodes
kubectl get pods --all-namespaces

Conclusion

You’ve now set up a single-node Kubernetes cluster on Linux. You can start deploying applications using YAML manifests, experiment with scaling, and explore the full power of container orchestration using Kubernetes.

Exit mobile version