GETTING STARTED WITH KUBERNETES – PART 1

Hello, welcome to my Kubernetes (K8s )post.

In today’s post, we’ll take a look at Kubernetes and container orchestration in general, and then we’ll deploy a Flask-based microservice (along with Postgres and Vue.js) to a Kubernetes cluster locally.

This post would be in 3 series because of the complexity of Kubernetes.

  1. Understanding Container Orchestration, Components and Architecture of K8s, Setting Up Minikube and understanding Kubectl CLI Commands
  2. Some elements of Kubernetes Objects like Kubernetes Secrets, ConfigMap, Volumes, Deployment, StatefulSet, Namespaces, Ingress and K8s Configuration YAML file
  3. Then, Hands-on experience, Running our Containerized Flask Microservice (that we created here ) on Kubernetes.

 

By the end of this tutorial, you will be able to:

  1. Understand what is  container orchestration and why you need it
  2. Discuss the architecture of a Kubernetes cluster ( master and worker nodes)
  3. Setting up your local system (personal laptop) for Kubernetes
  4. Basic Kubectl CLI commands

 

In my last post here, I talked about containerization and we did a simple app where we ran the following Flask, Vue, and PostgreSQL in containers.

So we are going to look at orchestrators.

Orchestrators are tools used to manage, scale, and maintain containerized applications, and a  common example is KubernetesDocker Swarm, and OpenShift by RedHat.

 

What is container orchestration?

Container orchestration is the automation of all aspects of coordinating and managing containers.

Container orchestration automates the deployment, management, scaling, and networking of containers.

THE NEED FOR ORCHESTRATION

Container orchestration is used to automate the following tasks at scale.

  • Configuring and scheduling containers
  • Provisioning and deployments of containers
  • Load balancing and traffic routing
  • Health monitoring of containers
  • Securing the interactions between containers.

 

 Kubernetes

Kubernetes is an open-source container orchestration tool that allows you to build application services that can schedule multiple containers across a cluster, scale those containers, manage their health over time, and eliminates many of the manual processes involved in deploying and scaling containerized applications.

LET ME EXPLAIN A SIMPLE REAL LIFE SCENARIO ON HOW K8s WORKS

Assuming that we deployed this, our containerized Note taking app on AWS.

Supposing our application goes down, our users may lose access to our app, in order to solve this and reduce such occurrence. We decide to use K8s (Kubernetes).

Kubernetes solves this issue by creating multiple copies or replicas of our Note App( same application )and make it highly available.

Benefits of Kubernetes
  • High availability, our containerized app is accessible by users
  • Scalability ( scales our containerized app to have high performance)
  • Disaster recovery has the ability to backup and restores our containerized applications to the previous state.

 

COMPONENTS OF KUBERNETES

When you deploy Kubernetes, you get a cluster.

Kubernetes cluster includes one master node and many worker machines called nodes.

Image Source: fosstechnix

Components of WORKER NODES

A node may be a virtual or physical machine, depending on the cluster. Each node contains the services necessary to run pods managed by the control plane (the master node).

Kubernetes runs your workload by placing containers into Pods to run on Nodes.

WHAT ARE PODS?

Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.

Pod is a group of one or more containers, with shared storage/network resources, and a specification for how to run the containers.

The component on a node includes the

  • Kubelet Service: It is responsible for setting pod requirements, such as mounting volumes, starting containers, and reporting status.
  • container runtime: The container runtime is the software that is responsible for running containers. Kubernetes supports several container runtimes such as Docker, contained and CRI-O, etc
  •  Kube-proxy:  It implements Kubernetes service concepts such as giving Pods their own IP addresses, a single DNS names for a set of Pods,  load-balancing across them.

 

master node

The master node manages the worker nodes and the pods in the cluster.

The control plane’s (master node)components include the following

  • kube-apiserver :  It is a cluster gateway that gets queries or updates from the clusters. It is used to create, delete, and update any object inside the cluster using the kubectl command.
  • etcd : is a key-value store of the cluster state, eg when a pod dies, rescheduled, such information is recorded on etcd.
  • kube-scheduler : Scheduler is responsible for physically scheduling pods across multiple nodes after kube-apiserver validates request from the cluster.
  • kube-controller-manager : It is  responsible for the overall health of the entire cluster, such as no of nodes insides the cluster, up and running status. For E.g .when a pod dies, the Controller manager makes a request to the Scheduler to schedules those pods.

 

Setting Up Kubernetes [Locally]

kubectl

The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.

Follow the guide here and install it for your OS, I am currently using macOS Catalina, will run the command below

brew install kubectl

Check the version installed:

$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:50:19Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"darwin/amd64"

 

minikube

minikube is a tool that lets you run Kubernetes locally. minikube runs a single-node Kubernetes cluster on your personal computer (including Windows, macOS, and Linux PCs) so that you can try out Kubernetes.

Follow the guide here and install for your OS,

brew install minikube

To check if our installation is complete

$ minikube version  
minikube version: v1.15.1
commit: 23f40a012abb52eff365ff99a709501a61ac5876
Container or virtual machine manager

HyperKit is an open-source hypervisor for macOS hypervisor, optimized for lightweight virtual machines and container deployment.

brew install hyperkit

Specify a virtual box for your minikube and start up the Cluster

minikube start --driver=hyperkit

Pull up the Minikube dashboard

minikube dashboard

Kubectl CLI Commands

minikube start Starts a local Kubernetes cluster
minikube ip Displays the IP address of the cluster
minikube dashboard Opens the Kubernetes dashboard in your browser
kubectl version Displays the Kubectl version
kubectl cluster-info Displays the cluster info
kubectl get nodes Lists the Nodes
kubectl get pods Lists the Pods
kubectl get deployments Lists the Deployments
kubectl get services Lists the Services
minikube stop Stops a local Kubernetes cluster
minikube delete Removes a local Kubernetes cluster

 

Conclusion

We brushed the components of Kubernetes Clusters, some Kubectl CLI command and set it up locally.

So my next post we look  at Kubernetes Objects like Namespace, Ingress, and Understanding K8s Configuration File

REFERENCES

 

Leave a Reply

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