5 Important Kubernetes Concepts Made Easy
Getting Started with Kubernetes is NOT easy. This article will help you understand some of the most important concepts of Kubernetes.
Kubernetes is the most popular open-source container orchestration solution.
Getting Started with Kubernetes is NOT easy.
This article will help you understand some of the most important concepts of Kubernetes.
1. Why do we need Container Orchestration?
2. What is Container Orchestration?
3. What is Kubernetes?
4. What are the most important Kubernetes concepts?
1. What is a Cluster?
2. Let’s Deploy a microservice
3. What is a Pod?
4. What is a ReplicaSet?
5. What is a Deployment?
6. A Quick Review - Deployment vs Replica Set
7. What is a Service?
5. Next Steps
1. Why Do We Need Container Orchestration?
Most enterprises are adopting microservices architectures.
Microservices provide the flexibility to innovate.
However, microservices don’t come for free. Instead of deploying a few applications, we are deploying hundreds of microservices. This results in increased complexity.
Containers can help simplify your deployment and observability challenges. However, there are still challenges with respect to managing your infrastructure and deployments. Example: I want 10 instances of microservice A container, 15 instances of microservice B container, .. and so on for multiple microservices. In addition, I want a number of other features for my microservices. A few typical features include:
- Auto Scaling - Scale containers based on demand
- Service Discovery - Help microservices find one another
- Load Balancer - Distribute load among multiple instances of a microservice
- Self Healing - Do health checks and replace failing instances
- Zero Downtime Deployments - Release new versions without downtime
2. What Is Container Orchestration?
Container orchestration solutions provide the most technical features needed by microservices architectures. You will be able to create a cluster of multiple VM instances and deploy microservices to the cluster. The container orchestration solution will manage the clusters and deployments.
3. What Is Kubernetes?
There are a number of container orchestration platforms: Docker Swarm, Mesosphere, and Kubernetes among others. In the last few years, Kubernetes has emerged as the winner in the container orchestration space.
4. What Are the Most Important Kubernetes Concepts?
Let’s say you want to set up a microservices architecture with Kubernetes. Here’s what the workflow would look like:
- Step 1: Create a Kubernetes cluster with container orchestration of multiple nodes (or virtual machines)
- Step 2: Deploy and configure your first microservice
- Step 3: Deploy and configure your second microservice
Let’s now look at each of these in depth.
4.1. What Is a Cluster?
A cluster is a group of virtual machines. In the cluster, there are two types of nodes:
- Master Node(s) - Manages the cluster. You send all your deployment instructions to the master node.
- Worker Node(s) - All microservices run on the worker nodes.
Here are some of the important Master Node (Control plane) components:
- API Server - Handles all communication for a K8S cluster (from nodes and outside)
- Scheduler - Decides placement of pods
- Control Manager - Manages deployments & replica sets
- etcd - Distributed database storing the cluster state
The job of a worker node is to run your microservices. In addition, a Kubernetes component called a Kubelet runs on each pod. Kubelet enables worker nodes to communicate with the master node(s).
4.2. Let’s Deploy a Microservice
Let’s say I want to deploy 5 instances of V1 of microservice A. The command to issue to create a deployment and set a number of instances for it is similar to what you see below:
This would deploy v1 of your microservice A with 5 instances to the Kubernetes cluster.
Internally, Kubernetes would create
- A Deployment
- A ReplicaSet and
- 5 Pods
Why does Kubernetes do this?
Let’s dig deeper.
4.3. What Is a Pod?
A pod is the smallest deployable unit in Kubernetes. A pod represents an instance of your microservice. Each Pod is assigned an ephemeral IP address.
If I have 10 instances of Microservice A and 12 instances of microservice B running in a Kubernetes cluster, then I would have a total of 10 + 12 = 22 pods running.
4.4. What Is a ReplicaSet?
We deployed microservice A with 5 instances to the Kubernetes cluster. This would mean that you have 5 pods running. Let’s say you kill one of the pods. Kubernetes would automatically recognize this and create a replacement pod. Kubernetes monitors the health of your pods and replaces unhealthy pods. How does Kubernetes do this?
This is the job of a ReplicaSet.
A ReplicaSet ensures that a specified number of pods are always running. In the above example, a ReplicaSet ensures that 5 instances of microservice A are always running.
4.5. What Is Deployment?
If a ReplicaSet ensures a specific number of pods, what is the role of Deployment?
A deployment ensures that you have flexibility when you release new versions of your microservices.
A deployment represents all the versions of your microservice.
Currently, we have just one version of the microservice. However, you can deploy a new version. Let’s say, I want to deploy V2 of microservice without any downtime.
That’s the job of a Deployment.
When you deploy a new version of an existing microservice, the Deployment would create a new ReplicaSet for V2 of microservice A.
You will have:
- One Deployment representing the microservice A
- One ReplicaSet for V1 of microservice A
- One ReplicaSet for V2 of microservice A
4.6. A Quick Review - Deployment vs Replica Set:
A deployment is created for each microservice. A Deployment represents a microservice (with all its releases). A Deployment manages new releases ensuring zero downtime.
A Replica set ensures that a specific number of pods are running for a specific microservice version. Even if one of the pods is killed, the replica set will launch a new one.
When you deploy a V2 of microservice, a new ReplicaSet (V2 ReplicaSet) is created.
Deployment updates V1 Replica Set and V2 Replica Set based on the release strategies configured.
4.7. What Is a Service?
In Kubernetes, each Pod has its own IP address. How do you ensure that external users are not impacted when:
- Either a pod fails and is replaced OR
- A new version of the microservice is deployed and all existing pods of the old release are replaced by ones of the new release
Solution: Create a Service.
A service exposes your deployments to the outside world using a stable IP address. This ensures that your users are not impacted as pods go down and come up.
There are three types of services:
- ClusterIP: Exposes Service on a cluster-internal IP. Use case: You want your microservice only to be available inside the cluster (Intra cluster communication).
- LoadBalancer: Exposes Service externally using a cloud provider’s load balancer. Use case: You want to create individual Load Balancers for each microservice.
- NodePort: Exposes Service on each Node’s IP at a static port (the NodePort). Use case: You DO not want to create an external Load Balancer for each microservice (You can create one Ingress component to load balance multiple microservices).
5. Next Steps
a Kubernetes cluster in one of the cloud platforms and play with it (GKE
has a free tier. You can try AKS and EKS but they are not part of the free
tier as of now!).
We Provide consulting, implementation, and management services on DevOps, DevSecOps, Cloud, Automated Ops, Microservices, Infrastructure, and Security
Services offered by us: https://www.zippyops.com/services
Our Products: https://www.zippyops.com/products
Our Solutions: https://www.zippyops.com/solutions
For Demo, videos check out YouTube Playlist: https://www.youtube.com/watch?v=4FYvPooN_Tg&list=PLCJ3JpanNyCfXlHahZhYgJH9-rV6ouPro
If this seems interesting, please email us at [email protected] for a call.
Architectural Patterns for Microservices With Kubernetes
Searchable Pod Logs on Kubernetes in Minutes
O11y Guide: Keeping Your Cloud-Native Observability Options Open
Leave a Comment
We will be happy to hear what you think about this post