Understanding Microservices: A Beginner’s Guide to Kubernetes (Day 21)

Araiz bin Saqib
5 min read5 days ago

--

Hey Everyone!

In our previous discussion, we delve into Jenkins. If you haven’t read it yet, you can check it out [here].

Today, we will see Kubernetes in more detail.

What is Kubernetes?

Kubernetes is an open-source container orchestration engine designed for automating the deployment, scaling, load balancing, and management of containerized applications. This open-source project is hosted by the Cloud Native Computing Foundation (CNCF).

Before being named Kubernetes, it was known as ‘Project Seven’. It was originally a Google project, created in 2013 using the Go programming language (Golang). Initially, Kubernetes was not open source, but in 2014, Google donated it to the Cloud Native Computing Foundation (CNCF). Kubernetes is essentially a container management tool.

Languages Supported by Kubernetes:
Kubernetes supports both YAML and JSON for configuration.

Understanding of Kubernetes and Docker

To grasp Kubernetes, also known as K8s, it’s essential to have a foundation in Docker. In Docker, we deploy our applications inside containers. However, in Kubernetes, we manage containers on a larger scale, often numbering in the thousands or more, depending on the application’s traffic.

Visualizing Docker and Kubernetes

In Docker, imagine a ship containing containers.

Now, in Kubernetes, picture that same ship, but this time, it has a steering wheel. Just like a captain operates the ship’s wheel to make decisions about its course, Kubernetes acts as the “ship wheel” for managing containers.

Kubernetes is an open-source platform, meaning its source code is freely available for anyone to use, modify, and redistribute.

What are Monolithic Architecture and Microservices Architecture?

Monolithic Architecture:

Mono means single and lithic means stone, hence single stone. Imagine an application like Facebook where all its business logic or code is written in one big codebase. This codebase handles login, posts, stories, and the news feed all in a single place.

In this scenario, if you want to scale a specific module, like the news feed, or if there’s a problem with one part of the code, it can affect the entire application’s operation. If you change the code in one module, the entire application might be affected because the code is interconnected. Any changes to any part of the code will require careful consideration of the entire application, which can lead to significant challenges in maintaining and scaling the application.

Microservices Architecture:

Now, consider a service like Facebook. Instead of one big codebase handling everything, Facebook could be divided into a network of different services, each specializing in a specific function like login, posts, stories, or news feed.

When you use Facebook, each service (microservice) handles its own part of the application independently. These services work together to create a seamless experience for the user.

If one service has an issue, it doesn’t necessarily impact the others. For example, if the news feed service is experiencing high traffic, it won’t affect the login service’s ability to let users sign in. Every service aka server has its own database.

Key Differences:

  • Monolithic architecture is like a single codebase handling all tasks, while microservices architecture is like multiple specialized small services working together.
  • Monoliths are typically easier to set up and manage initially, while microservices offer more flexibility and scalability.
  • Monoliths can have a single point of failure, while microservices are more fault-tolerant because a failure in one microservice doesn’t necessarily affect the others.

In the end, Kubernetes helps to achieve microservice-based architecture which is good for business aspects, etc.

Why do we need Kubernetes?

After Docker came into the picture, deploying applications on containers became very easy because containers are lightweight. However, over time, several issues arose, particularly in managing a large number of containers in production environments. Containers failing led to significant business losses.

That’s when Kubernetes came in. It automates many tasks, such as:

  • Auto-scaling: Kubernetes automatically scales containers according to peak or normal hours, depending on user traffic.
  • Load balancing: It ensures that requests are evenly distributed across multiple containers. For example, if there are 10 containers, Kubernetes balances the requests/tasks between them, ensuring no single container is overburdened.
  • Automated deployment: Kubernetes automatically deploys containers to available nodes in the cluster.
  • Self-healing: If containers fail, Kubernetes automatically restarts or replaces them to maintain the desired state of the application.

Features of Kubernetes

  • AutoScaling: Kubernetes supports two types of autoscaling horizontal and vertical scaling for large-scale production environments which helps to reduce the downtime of the applications.
  • Auto Healing: Kubernetes supports auto healing which means if the containers fail or are stopped due to any issues, with the help of Kubernetes components(which will talk in upcoming days), containers will automatically repaired or heal and run again properly.
  • Load Balancing: With the help of load balancing, Kubernetes distributes the traffic equally between two or more containers.
  • Platform Independent: Kubernetes can work on any type of infrastructure whether it’s On-premises, Virtual Machines, or any Cloud.
  • Fault Tolerance: Kubernetes helps to notify nodes or pods failures and create new pods or containers as soon as possible
  • Rollback: You can switch to the previous version.
  • Health Monitoring of Containers: Regularly check the health of the monitor and if any container fails, create a new container.
  • Orchestration: Suppose, three containers are running on different networks (On-premises, Virtual Machines, and On the Cloud). Kubernetes can create one cluster that has all three running containers from different networks, hence it supports hybrid network also.

Alternatives of Kubernetes(container serives types)

  • Docker Swarm
  • Apache Mesos
  • Openshift
  • ContainerD, etc

We don’t need to know the other alternative in depth except Docker Swarm as our main focus is Kubernetes.

Difference between Docker Swarm and Kubernetes

Master-Slave/ Client-Server Architecture in Kubernetes or K8s Cluster:

  • Master node: This is a server where Kubernetes components like the API server, scheduler, and controller manager are installed. It manages the entire Kubernetes cluster.
  • Node/worker: This is a machine (physical or virtual) in the cluster that runs pods. Each node can contain multiple pods.
  • Pod: This is the smallest deployable unit in Kubernetes. Kubernetes manages containers through pods. A pod can contain one or more containers, although typically there is only one container per pod.
  • Container: This is where our application runs. It encapsulates the application along with its dependencies.

The structure is as follows:
Cluster -> Node -> Pod -> Container -> Application/MicroService running

Conclusion:
And there you have it — a glimpse into the fascinating world of Kubernetes. We’ve covered the basics, understanding its roots, and how it compares to Docker. In the days to come, we’ll dive deeper into the inner workings of Kubernetes, exploring its features, architecture, and much more.

Follow me as we unravel more Kubernetes mysteries!

Feel free to reach out to me, if you have any other queries.

Happy Learning :)

--

--