Kubernetes Certification Training Course : Lecture 1

What is Kubernetes all together ? Kubernetes is Container Orchestration Tool that solves common Infrastructure and Devops challenges :

  • Which Node suits the Container Requirement
  • Maintain the Desired State
  • How to Share the Load (User Requests)
  • Scalability
  • Auto Healing
  • Auto Scaling
  • Zero Downtime Upgrades / Rollbacks
  • Containers & NODEs Communication
  • Security

There are several orchestration tools :

  • Amazon ECS from Amazon
  • Azure Container Services from Microsoft
  • Docker Swarm (Docker Opensource Tools)
  • Google Container Engine (from Google Cloud Platform)
  • Kubernetes (Docker Opensource Tools)
  • CoreOS Fleet (from CoreOS)
  • Mesosphere Marathon (from Marathon)
  • Cloud Foundry’s Diego (from Cloud Foundry)

Kubernetes is the best orchestration platform. And Kubernetes itself is not a containerization platform, it cannot create or run an image, it is used for managing the containers. To run containers, a containerization technology is used. In other words, a Docker (or another containerization tool: ContainerD, CRIO etc , Kubernetes is compatible with many containerization tools) has to be installed on machines along with Kubernetes.

Kubernetes follows multi-machine Master-Node architecture. Everything is managed from Master machine. And there are associated Nodes, controlled by Master. The combination of Master and Nodes is called Kubernetes Cluster. At Master level there are four important components :

  • Api-Server
  • Scheduler
  • etcd
  • Controller Manager

At Node level two important components are used :

  • kubelet 
  • proxy

For communicating with Kubernetes kubectl is used. kubectl is a client utility used for communicating with Kubernetes. For communicating with Kubernetes an Api-Server component of Master  is used, it manages the whole infrastructure of Kubernetes. Talking to Kubernetes Master is actually talking to Api-Server. All Api-Server information is available on /etc/kubernetes/admin.conf file.

Scheduler is used for scheduling the kubernetes activities. Suppose, for running a container Api-Server announces it. Then Scheduler immediately checks : how many Nodes are in the system, how many Nodes are available, how many Nodes can take the workload, their free space etc – that is the way the Scheduler finds the best way to run a Container.

etcd is a key-value pair database (like MongoDB, Redis), that has all the information about associated Kubernetes cluster. It is an internal database of a Kubernetes. It is also used for restoring the data in case of any crashes.

Controller Manager is used for controlling the running containers. If one container is down, it brings another automatically. If some of the Node(s) is not available, it ensures that no containers will be run on this Node. Controller Manager manages the desired state of the Kubernetes Cluster.

kubelet is the agent of the Node. kubelet manages all the containers on the Node and reports back to manager. It takes the instructions from Api-Server (Master) and reports back to Api-Server (Master).

proxy is used for request routing. Suppose, a use is requesting an application on the Node. proxy forwards the requests.

Like it was said above, so called Container Runtime Interface (containerization tool) must be installed on every machine in Kubernetes Cluster (even on Master). Usually it is Docker.

Example: Whenever administrator/developer wants to run a container, it addresses to Api-Server through kubectl (kubectl create … or kubectl apply …). Api-Server creates the information within the Cluster. The Scheduler goes and checks for the best Node to run a container and turns this information back to Api-Server. Api-Server accepts the information and turns to kubelet on the chosen Node. kubelet then interacts with CRI (Docker) for creating the container. Docker does all the work (pulls or creates the image, runs the container) and informs kubelet, which in turn informs Api-Server that the container runs. Then Api-Server tells etcd to save (persist) the information. Controller Manager will be looking after the container (whether it works properly).

Kubernetes has two ways to install the software :

  • KubeAdm
  • HardWay

With HardWay, every Kubernetes Cluster component must be installed and set up manually. KubeAdm is easier, KubeAdm itself installs Api-Server, Scheduler, etcd, Controller Manager and establishes communication across all components automatically. So KubeAdm must be installed first, and then kubectl and kubelet must be installed explicitly. KubeAdm, kubectl and kubelet must be installed on every Node in the Cluster. After that, one of the Nodes must be selected as a Master. With KubeAdm, all Kubernetes components (Api-Server, Scheduler, etcd, Controller Manager) are run as containers only. And containers are launched by CRI (usually Docker). That is why CRI and kubelet must be installed on Master as well – for running Master components as containers.

The steps for installing all necessary components for using Kubernetes on both Master and Nodes machines are (with code snippets for installing on Ubuntu) :

    1. Installing docker and kubeadm, kubectl, kubelet on all machines: Master and all Worker Nodes (along with security related instructions for working with https)
      sudo apt-get update
      sudo apt-get install -y apt-transport-https ca-certificates curl 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 ; clear
      sudo apt-get install -y docker-ce
      sudo service docker start ; clear
      
      echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
      curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
      sudo apt-get update ; clear
      sudo apt-get install -y kubelet kubeadm kubectl

      // after executing all commands watch console output and save the fragment matching the template kubeadm join <ip address>:<port> --token <token value> --discovery-token-ca-cert-hash <hash value>
  1. Installing Api-Server, Scheduler, etcd, Controller Manager on Master (also it is a good practice to import Api-Server information (/etc/kubernetes/admin.conf file) to user home directory (it is like setting environment variable on a user level) ). Installing so called CNI (Container Network Interface) for networking capabilities on Master. Kubernetes can use any Container Runtime Interface (Docker, CRIO, ContainerD), that is why Kubernetes does not provide predefined networking by default (set of choices is here).
    ## Installing Api-Server
    sudo kubeadm init --ignore-preflight-errors=all ## Importing Api-Server information
    sudo mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config ## Weave (Chosen Container Network Interface) kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
  2. Join worker Nodes to Master (use fragment saved after completing step 1)

Leave a Reply

Your email address will not be published. Required fields are marked *