Kubernetes |Why do we need kubernetes |Kubernetes Componets|Kubernetes Architecture| Features of Kubernetes

Java Technologies And Frameworks
13 min readSep 25, 2022

--

(1)why Kubernetes is so useful by going back in time
(2)What is Kubernetes?
(3)What are the challenges Without Container Orchestration ?
(4)Differences between Kubernetes and Docker Swarm?
(5) Components of Kubernetes.(Pod, Node, Cluster, Replica set, Service, Deployment, Secrets & ConfigMap, ETCD)
(6) Basics and Architecture of Kubernetes.
(7)What is Master Node in Kubernetes Architecture and Components of Master node?
(8)What is Worker Node in Kubernetes Architecture?
(9)Components of Worker Nodes:
(10)How Do Kubernetes Services Work?
(11)Kubernetes Features. (Automatica Beanpacking,service discovery & Load balancing,Storage orchestration, Self Healing, Secrets and Configuration management, Batch Execution, Automatic rollbacks & rollouts, Scaling).

Now, before moving forward in this blog , let me just quickly brief about containerization. So, before container came into picture the developer and tester had a pretty quarrel between them. This usually happens because what worked on dev environment may or may not work on testing side .Now to avoid that ,containers were introduced so that both developers and testers were on same page.

Let’s take a look at why Kubernetes is so useful by going back in time.

  • Day by day the number of internet users also increases who all are using the applications in todays fast moving IT world.
  • Basically the ecommerce applications like flipkart , walmart.. etc has huge demand for business support due to increase in service and users.
  • So these applications do not stop their applications using 1 or 2 containers.
  • Again due heavy demand and zero service down time companies are moving from monolithic architecture to Microservice architecture to efficiently manage and scale application with less overhead.
  • So that 100’s of containers are used in prod environment, to manage and scale up automatically, So that container management tool came introduced to manage more number of containers in prod environment.

What Is Kubernetes?

Kubernetes is an open source container orchestration engine or container management tool. It is written in Go-language

Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications.

  • K8s as an abbreviation results from counting the eight letters between the “K” and the “s”. Google open-sourced the Kubernetes project in 2014.
  • But the Cloud Native Computing Foundation (CNCF) now maintains the project.
  • The purpose of Kubernetes is to manage a containerized application in various types of physical, virtual, and cloud environments.

Note: Kubernetes is not a containerization platform. It is a multi-container management solution.

What are the challenges Without Container Orchestration ?

In the above diagram multiple services are running inside individual docker containers. Suppose we want to scale those containers , its bit tough as large scale complex application which increases cost to maintain services and complex to run side by side.

common challenges are :

  • Increases the cost of running container services.
  • Increases the size of bill amount from public cloud providers.
  • Increases the complexity of running if something newly added in production .
  • setting up services manually.
  • scaling up services running inside docker container is difficult task.
  • Manual work of fixing if a node crashes.

To avoid those things Container orchestration come. There are mainly 2 such engines kubernetes and Docker Swarm

Differences between Kubernetes and Docker Swarm
1)Installation & Cluster Configuration:
Installation is complicated; but once setup, the cluster is very strong.
Installation is very simple; but cluster is not very strong.
2)GUI
GUI is there in Kubernetes Dashboard.
There is no GUI.
3)Scalability
Highly scalable & scales fast.
Highly scalable & scales 5x faster than Kubernetes.
4)Auto-Scaling
Kubernetes can do auto-scaling.
Docker Swarm can not do auto-scaling.
5)Load Balancing
Manual intervention needed for load balancing traffic between different containers in different Pods.
Docker Swarm does auto load balancing of traffic between containers in the cluster.
6)Rolling Updates & Rollbacks
Can deploy Rolling updates & does automatic Rollbacks.
Can deploy Rolling updates, but not automatic Rollbacks.
7)Data Volumes
Can share storage volumes only with other containers in same Pod.
Can share storage volumes with any other container.
8)Logging & Monitoring
In-built tools for logging & monitoring.
3rd party tools like ELK should be used for logging & monitoring.

Components of Kubernetes

Pods:

  • Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.
  • Pods are the smallest, most basic deployable objects in Kubernetes. A Pod represents a single instance of a running process in your cluster. Pods contain one or more containers, such as Docker containers. When a Pod runs multiple containers, the containers are managed as a single entity and share the Pod’s resources.
  • Inside a pod the containers are sharing the storage and network resources.
  • In kubernetes are not directly interact with containers, the containers are packaged into a single unit call pods.
    one pod is having many containers or single container
    one pod is associated to a single ip address.so one pod can communicate to another pod also.

Node

  • A Kubernetes Node is a logical collection of IT resources that supports one or more containers. Nodes contain the necessary services to run Pods (which are Kubernetes’s units of containers), communicate with master components, configure networking and run assigned workloads. A Node can host one or multiple Pods.
  • There is one physical or virtual machine where all pods wrapped in to a single unit called Node .
    A Node can have a single pod or can have multiple pod .

Cluster

  • Multiple pod can wrapped into a physical unit i.e called cluster.
    A Cluster can have single node or can have multiple nodes.
  • A Kubernetes Cluster comprises of one master node and a number of worker nodes. These nodes can be a physical machine
    or may be virtual machine depending upon the cluster creation.
  • A Kubernetes cluster consists of a set of worker machines, called nodes, that run containerized applications. Every cluster has at least one worker node. The worker node(s) host the Pods that are the components of the application workload. The control plane manages the worker nodes and the Pods in the cluster.

Replication controller / Replica sets

  • lets assume I have database image and I am pulling that image and created in database pod-1.
    As we know each application wants to interact with database pod , due to some problem my database pod got crashed ,so to manage that there is no alternative. our application downs .Replica sets came onto pictures to solve the down time.
  • Replica is nothing but k8s bring up with a new pod from the replica set and assign a new ip to the newly created pod .
    This replica set we will create at the time of deployment object.

Service

  • Example frontend pod (10.100.90)where an react application is running backend -pod(10.100.80) where
    spring boot application is running. Each pod is assigned with ip address and
    frontend pod will communicate with backend pod using the ip address.
  • if any pod crash then replica set come up with new pod from replica set with new ip address.
    so we understood here that ip address is keep on changing if any crash and down time of pod happens.
    problem is frontend pod cant communicate with backend pod using the old pod ip address.
    So service came into picture to solve the problem.
    each pod can associated to a single service or multiple pod can associated or grouped together into a single service
    with level and selector.
  • For now in the example frontend pod is assigned with a static ip address and DNS name.
    Going forward each pod will communicate using the DNS name. so if any backend pod will crash Replica set will
    replace a new backend pod .
    It wont impact to frontend pod because frontend pod still connect to backend pod with service DNS name.
    Apart from life cycle management service also play a vital role to load balancer where traffic will be
    managed by service based on incoming traffic to a pod.
  • service will redirect to available pod based on traffic or load.

Deployment

  • Deployments are kubernetes objects that are used for managing pods.
    you can scale our application by increasing the number of running pods or
    update the running application i.e pods using the deployment object.
    we can update also memory ,cpu’s, no of pods using deployment objects.
  • command
    kubectl create deployment spring-first-deployment-
    image=<Docker_Image_Name> — port=8080 — replicas=4
  • this command tells create deployment object with name spring-first-deployment
    then pull docker image from local docker repository or from docker hub
    and then create active pod with 4 replica (backup of actual pod)pods.
  • Alternatively we can use deployment object using deployment.yml file.

Secrets and ConfigMap

  • Both secret and config map is used to store the sensitive information like password of database and password of application like secrets key and api key .
  • Suppose for spring boot application we are storing the database password in application.properties or application.yml file.
  • Suppose the configuration will change we need to rebuild docker image again and deploy to container. so we can manage this configuration out side of the application. So that we are using here the containerization plat form , so we directly configure it in k8s components to store the sensitive information.
  • These 2 components secrets and configmap present outside of the pods. If there are multiple pods inside a Node so they can use the same secrets and configmap.
  • Secrets will store the encrypted db password.
    ConfigMap will store plain text like Api Url and db username and etc.

ETCD

  • Kubernetes uses the etcd as a key-value database store.
    It stores the configuration of the kubernetes cluster in etcd.
    Also it stores all the secrets and ConfigMap data inside etcd database.
    The max limit of store secrets is 1MB.

Basics and Architecture of Kubernetes

Architecture of Kubernetes

In Kubernetes there is always a master node and multiple worker node.

What is Master Node in Kubernetes Architecture?

Master node manages the cluster and basically monitor the node and pods inside a cluster.

Master node has 4 components

API Server
Scheduler
Controller manager
ETCD

Master node Diagram: Kubernetes Master Node

API Server :

  • The API Server is the front-end of the control plane and the only component in the control plane that we interact with directly. Internal system components, as well as external user components, all communicate via the same API.
  • It acts as cluster gateway . Each request coming to cluster will first serve by API server.
    It exposes few of the API to access all the operations going on inside the cluster. we can access the API server using the command line tool kubectl or k8s UI. To check the health of Nodes and pods use kubectl get pods and kubectl get nodes.
  • The API server of master node receives the request and get all the details of application
    running inside the worker node.

Scheduler:

  • It schedules pods across multiple nodes.
    To scale up a node first Scheduler checks the pods and its cpu usage and memory of each worker node and based on availability it will assign the pods to specific node.
  • A Scheduler watches for new requests coming from the API Server and assigns them to healthy nodes. It ranks the quality of the nodes and deploys pods to the best-suited node.

ETCD

The scheduler will get all those info from ETCD which is having cluster, nodes and node details like cpu usage.

Controller Manager

  • It will checks or detects cluster state change like the which node or pods is crashed and what is the backup or replica pods for that node.
    when a pod crashed K8s immediately create a new pod from replica set and then controller manager will talk to scheduler to schedule a new pod to an availability nodes.
  • Again controller manager manages the multiple controller.
  • Node controller — monitor and control all node activity.
    Replication Controller — monitor health of pod if any pod is down create a new from replica set.
    Endpoints Controller- manages all service and their communication
    Service account and token controller — responsible for account and API access & name spaces.

What is Worker Node in Kubernetes Architecture?

Components of Worker Nodes:

Kubernetes Worker Node
  • It is a physical or virtual machine where multiple pods are running.
    It has 3 components.
    kubelet
    kube-proxy
    container runtime

kubelet:

  • kubelet is an agent running on each node. kubelet communicate with master node with the help of API server.It watches for tasks sent from the API Server, executes the task, and reports back to the Master. It also monitors pods and reports back to the control panel if a pod is not fully functional. Based on that information, the Master can then decide how to allocate tasks and resources to reach the desired state.
  • kubelet works in terms of PodSpec. PodSpec is a yml or json object that describes about our pods.
  • kubelet takes set of ProdSpec and describes the containers running inside ProdSpec are running healthy.
  • Kubelet manages the container which only created by Kubernetes only.
  • It watches for tasks sent from the API Server, executes the task, and reports back to the Master. It also monitors pods and reports back to the control panel if a pod is not fully functional. Based on that information, the Master can then decide how to allocate tasks and resources to reach the desired state.

Kube-proxy

  • kube-proxy is a network agent which runs on each node and it is responsible for network configuration and rules.
  • These rules allow the network communication between pods from inside and outside of cluster.
    Basically helps to expose our services outside world.Kube-proxy also communicate with master node using the API server.rules to handle routing and traffic load balancing.

Container Runtime

  • Container runtime also known as container engine , helps to run container inside pods.
  • Provides support to all the wrapped container inside a single pods or multiple pods.
  • The container runtime pulls images from a container image registry and starts and stops containers. A 3rd party software or plugin, such as Docker, usually performs this function.

How Do Kubernetes Services Work?

  • Pods are associated with services through key-value pairs called labels and selectors. A service automatically discovers a new pod with labels that match the selector.
  • This process seamlessly adds new pods to the service, and at the same time, removes terminated pods from the cluster.
  • For example, if the desired state includes three replicas of a pod and a node running one replica fails, the current state is reduced to two pods. Kubernetes observers that the desired state is three pods. It then schedules one new replica to take the place of the failed pod and assigns it to another node in the cluster.
  • The same would apply when updating or scaling the application by adding or removing pods. Once we update the desired state, Kubernetes notices the discrepancy and adds or removes pods to match the manifest file. The Kubernetes control panel records, implements, and runs background reconciliation loops that continuously check to see if the environment matches user-defined requirements.

Features Of Kubernetes

Kubernetes Features — What Is Kubernetes

1. Automatic Binpacking

Kubernetes automatically packages your application and schedules the containers based on their requirements using docker containerization and available resources . To ensure complete utilization and save unused resources, Kubernetes balances between critical and best-effort workloads.

2. Service Discovery & Load balancing

With Kubernetes, there is no need to worry about networking and communication because Kubernetes will automatically assign IP addresses to containers and a single DNS name for a set of containers, that can load-balance traffic inside the cluster.

3. Storage Orchestration

With Kubernetes, you can mount the storage system of your choice. You can either go for local storage, or choose a public cloud provider such as GCP or AWS or Azure, or perhaps use a shared network storage system such as NFS, iSCSI, etc.

4. Self-Healing

Kubernetes can automatically restart containers that fail during execution and kills those containers that don’t respond to user-defined health checks. But if nodes itself die, then it replaces and reschedules those failed containers on other available nodes.

5. Secret & Configuration Management

Kubernetes can help you deploy and update secrets and application configuration without rebuilding your image and without exposing secrets in your stack configuration.

6. Batch Execution

In addition to managing services, Kubernetes can also manage your batch and CI workloads, thus replacing containers that fail, if desired.

7. Horizontal Scaling

Kubernetes needs only 1 command to scale up the containers, or to scale them down when using the CLI. Else, scaling can also be done via the Dashboard (kubernetes UI).

8. Automatic Rollbacks & Rollouts

Kubernetes progressively rolls out changes and updates to your application or its configuration, by ensuring that not all instances are worked at the same instance. Even if something goes wrong, Kubernetes will rollback the change for you.

Note:

  • Kubernetes is an example of a container management system developed in the Google platform.
  • The biggest advantage of using Kubernetes is that it can run on-premises OpenStack, public clouds Google, Azure, AWS, etc.
  • Kubernetes offers automated Scheduling and Self-Healing Capabilities.
  • Cluster, master, node, and namespace are important basic of kubernetes
  • Replication Controllers, Replication sets, Deployments, Stateful Sets, Daemon Sets are other important terms used in Kubernetes.
  • Docker swarm does not allow auto-scaling while Kubernetes allows auto-scaling.

Thanks for reading!! Please do follow the JTF.

--

--