Understanding Kubernetes Architecture

Kubernetes Architecture and Components, Kubernetes Installation and Configuration

Monday

Tasks

  • Understand Kubernetes Architecture

  • Understand Kubernetes objects

Kubernetes Architecture

  • kubectl

    • this tool is used to interact with the Kubernetes cluster

    • communicated via the `API-server

  • control plan

    • API-server

      • this is the interface into the cluster used for communication with the nodes in the cluster
    • etc

      • this is a key-pair database about the cluster
    • scheduler

      • determines which node containers should be provisioned in
    • controller-manager

      • checks and ensures that the desired state of the node is equal to the actual state. this process is referred to as self-healing. An unreachable node will be replaced with a new one by the controller manager
  • worker node

    • kubelet

      • takes instructions from the api-server for managing the node and its components
    • cri

      • this is the docker software installed with Kubernetes. takes instructions from Kubelet for the creation of containers

      • cri adhers to the cri standards and can be docker or dockerd or any compliant container service

    • kube-proxy

      • provides networking that allows containers to communicate with each other. cni has to be installed separately for this to work

image.png

Setting up Kubernetes on Google Cloud

Google Cloud offers a higher capacity vm that can run Kubernetes unlike that offered by AWS for the free tier t2.micro.

The setup done in this writeup is therefore performed on Google cloud

The OS used for the setup is Ubuntu 18

The following are software that needs to be installed:

  • Install Docker

  • Install cri-dockerd

  • Install Kubeadm, kubelet & kubectl

  1. Install Docker

The following commands are needed to install docker

sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installDocker.sh -P /tmp
sudo chmod 755 /tmp/installDocker.sh
sudo bash /tmp/installDocker.sh
sudo systemctl restart docker.service

2. Install cri-dockerd

  sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installCRIDockerd.sh -P /tmp
sudo chmod 755 /tmp/installCRIDockerd.sh
sudo bash /tmp/installCRIDockerd.sh
sudo systemctl restart cri-docker.service

3. Install kubeadm, kubelet, kubectl

sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installK8S.sh -P /tmp
sudo chmod 755 /tmp/installK8S.sh
sudo bash /tmp/installK8S.sh

Verify the installation to confirm all needed software installed correctly

docker --v

above should return a version of the install

Docker version 23.0.4, build f480fb1

cri-dockerd --version

The above should return information about the installed cri-dockerd version

cri-dockerd 0.3.0 (0de30fc)

kubeadm version -o short

The above should display the version of kubeadm installed

{Major:"1", Minor:"27", GitVersion:"v1.27.1", GitCommit:"4c9411232e10168d7b050c49a1b59f6df9d7ea4b", GitTreeState:"clean", BuildDate:"2023-04-14T13:20:04Z", GoVersion:"go1.20.3", Compiler:"gc", Platform:"linux/amd64"}

kubelet --version

The above should display the version of kubelet installed

Kubernetes v1.27.1

Next step is to initialise the control plan

sudo kubeadm init --cri-socket unix:///var/run/cri-dockerd.sock --ignore-preflight-errors=all

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

Next, we install the network driver with the following command

kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.1/manifests/calico.yaml

We next need to check the nodes setup with kubectl as follows:

kubectl get nodes

The above should list the nodes as shown below

image.png

On to Setting up the worker node

We need to setup docker & Kubernetes on the worker node with the following commands:

sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installDocker.sh -P /tmp
sudo chmod 755 /tmp/installDocker.sh
sudo bash /tmp/installDocker.sh
sudo systemctl restart docker.service


Install CRI-dockerd
sudo chmod 755 /tmp/installCRIDockerd.sh
sudo bash /tmp/installCRIDockerd.sh
sudo systemctl restart cri-docker.service

Install kubeadm, kubelet and kubectl

sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installK8S.sh -P /tmp
sudo chmod 755 /tmp/installK8S.sh
sudo bash /tmp/installK8S.sh

Validate installation

docker -v cri-dockerd --version kubeadm version -o short kubelet --version kubectl version --short --client

The above should produce similar results to the control plan validation

The last step in the setup is to have the worker node join the cluster. The join, run the following command:

kubeadm token create --print-join-command

Copy the kubeadm join token from the control plan and run with

--cri-socket unix:///var/run/cri-dockerd.sock as shown in example below & then run on worker nodes

example: kubeadm join 10.128.15.231:6443 --cri-socket unix:///var/run/cri-dockerd.sock --token mks3y2.v03tyyru0gy12mbt \ --discovery-token-ca-cert-hash sha256:3de23d42c7002be0893339fbe558ee75e14399e11f22e3f0b34351077b7c4b56