Installation Simple Kubernetes Cluster on Ubuntu Server 20.04

Prerequisites:

  • 2 or more Linux servers running Ubuntu 20.04
  • 3.75 GB or more of RAM
  • 2 CPUs or more
  • Internet Connection
  • Certain ports are open on your machines.
  • Swap disabled. You MUST disable swap for the kubelet to work properly.

My Environment:

Setup Kubernetes Ubuntu 20.04

1. Config Nodes and Patches Ubuntu

ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub stack@master
ssh-copy-id -i ~/.ssh/id_rsa.pub stack@worker1
ssh-copy-id -i ~/.ssh/id_rsa.pub stack@worker2
sudo apt-get update -y

2. Install Docker

sudo apt-get install -y wget gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io

3. Start and Enable Docker

sudo mkdir /etc/docker
cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
sudo systemctl enable --now docker
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker
sudo usermod -aG docker ${USER}
#login again for apply change
su - $USER
id
docker --version
docker ps

4. Disable SWAP

sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
sudo swapoff -a
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

5. Install Kubectl and Kubernetes

sudo apt-get update -y
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 kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

6. Initialize the Cluster and Master Node

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

7. Install Networking overlay

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
kubectl get node -o wide
kubectl get pod --all-namespaces

8. Join the Worker Nodes to Kubernetes Cluster

sudo kubeadm join 192.168.1.234:6443 --token axwp1d.XXXXXXXXXX \
--discovery-token-ca-cert-hash sha256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1e74
kubectl get nodes

9. Deploy application on cluster

kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml

--

--

--

Cloud Consultant | RHCSA | RHCE in Red Hat OpenStack | Google Cloud ACE | AWS SAA | LinkedIn: https://www.linkedin.com/in/achchusnulchikam

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Benefits to Students of Open Source

Message Queues Made Simple with SQS, Lambda, NodeJS, and Serverless

How many years experience do you have?

Earn btc https://use.foldapp.com/r/KEEJ94EP

Buffer Overflow Prep for OSCP-TryHackMe

The Automators Toolbox — What to start out with

DA-IICT welcomes applications from foreign nationals and non-resident Indians.

Discord a voice alternative for Opensim and virtual world education

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ach.Chusnul Chikam

Ach.Chusnul Chikam

Cloud Consultant | RHCSA | RHCE in Red Hat OpenStack | Google Cloud ACE | AWS SAA | LinkedIn: https://www.linkedin.com/in/achchusnulchikam

More from Medium

Deploy Kubernetes dashboard with NodePort

Adding Windows Node to K8S Cluster and Monitoring

Create GitLab Environment For Testing.

On premise kubernetes setup with metallb (layer 2) and nfs volume provisioner.