Open In App

What Are The Kubernetes Deployment Stratagies ?

Last Updated : 04 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Traditionally, applications used to be deployed on the Physical Servers. However, it was not very efficient as multiple instances of the applications running on the server used to consume a lot of resources. Although Virtual Machines running on the Servers tried to solve the issue, resource allocation and slow boot times were still problems. Due to this, Containerization Technologies like Kubernetes came into the picture.

In this article, we will learn in detail about the deployment strategies in Kubernetes that will help us to understand why it is one of the most popular choices among Software Experts. So, let us start without any delay.

What Is Kubernetes?

Kubernetes, abbreviated as K8s acts as the container orchestration platform to deploy and manage the containerized applications. It allows the system experts to manage the application workloads using the centralized control plane. Now, you might have the question in your mind what is the meaning of containerized applications? So, the container is the unit that encapsulates the applications including its dependencies like binaries, libraries, and configuration files.

Due to this, we can easily deploy the application across multiple environments. Within the Kubernetes, these containers are grouped into logical units called pods. One pod can contain more than one containers that share the same network namespace and storage volumes so that they can communicate with each other and access shared data.

Now, let us quickly have a look at the features of Kubernetes so that we can easily understand the deployment strategies.

Features Of Kubernetes

The following are the features of Kubernetes:

  • Multi-tenant Environment: Kubernetes supports multi-tenancy in the container environment. It means that multiple users or teams can share a cluster while maintaining isolation and resource quotas.
  • Container Orchestration: Kubernetes automates the deployment, scaling, and management of containerized applications. Hence, it provides the complete centralized platform for orchestrating containers across a cluster of machines.
  • Automatic Scheduling Of Nodes: Kubernetes schedules containers onto nodes within the cluster based on resource requirements, affinity, and anti-affinity policies. This optimizes the resource utilization and application performance.
  • Service Delivery And Load Balancing: Kubernetes has built-in mechanisms for service discovery and load balancing. It enables the containers to communicate with each other and distribute traffic across multiple instances of an application.
  • Rollback And Rollout Automatically: Kubernetes supports automated rolling updates to applications so that the new versions can be deployed with minimal downtime. It also supports rollback to previous versions in case of issues.

Understanding Of Kubernetes Deployment

Before going to the deployment strategies, first, let us understand what is deployment in Kubernetes. The deployment is a resource object used to manage the rollout and scaling of applications. This resource object defines the desired state of a set of identical pods and ensures that their actual state matches this desired state.

  • Deployment is done using the declarative model in which users just define the desired state of their applications and Kubernetes handles the details of deploying and managing the underlying infrastructure.
  • The deployment in Kubernetes helps us in managing the application’s life cycle. For example, we can define a number of pods and how should we update them. Thus, it is important to learn the deployment strategies.
  • An important fact to know about Kubernetes is that YAML stands for Yet Another Markup Language. It is used to define and configure various resources within the Kubernetes Environment. Let’s now learn the various deployment strategies.

Deployment Strategies In Kubernetes

There are different approaches through which we can manage our containerized applications. These different deployment strategies allow us to roll out the updates to the applications with minimal downtime. Let us see different strategies so that we can select the right deployment plan as per the requirements. The following are the some of the popularly known kubernetes Deployment Strategies:

1. Recreate Deployment Strategy

2. Rolling Update Deployment Strategy

3. Blue Green Deployment Strategy

4. Canary Deployment Strategy

5. A/B Testing Deployment Strategy

6. Shadow Deployment Strategy

Recreate Deployment Strategy

In Kubernetes, the Recreate Deployment Strategy is one of the simplest approaches to updating applications. This strategy down all existing pods of the previous version of the application and then creates new pods for the updated version. In other words, it terminates all running instances of the old version and replaces them with instances of the new version.

Recreate Deployment Strategy

  • The following YAML can be used to implement this kind of deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
strategy:
type: Recreate
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: my-image:latest

Use Case Of Recreate Deployment: Recreate deployment is suitable for applications that can tolerate downtime during the deployment process or for scenarios where the application’s state can be easily recreated.

Rolling Update Deployment Strategy

The Rolling Update Deployment Strategy is the most commonly used approach for updating applications. This approach gradually replaces the instances of the previous version of the application with instances of the updated version, one at a time. This reduces the downtime and improves the performance.

Rolling-Update Deployment Strategy

  • The following YAML can be used to implement this kind of deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: my-image:latest

Use Case For Rolling Update Strategy: Rolling update is ideal for applications that require high availability and cannot afford any downtime during the deployment. Thus, you can use It to switch from the old version to the new version while maintaining uninterrupted service.

Blue-Green Deployment Strategy

The Blue-Green Deployment focuses on running two identical environments, referred to as blue and green. An important point to note is that both these environments run concurrently. The blue environment represents the current production version of the application, while the green environment represents the new version being deployed.

Blue-Green

  • The following YAML can be used to implement this kind of deployment:
apiVersion: v1
kind: Service
metadata:
name: my-app-service
labels:
app: my-app
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: my-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-blue
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
color: blue
spec:
containers:
- name: my-app-container
image: my-image:blue
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-green
spec:
replicas: 0
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
color: green
spec:
containers:
- name: my-app-container
image: my-image:green

Use Case For Blue Green Deployment: This deployment is suitable for applications where zero downtime is important so that we can quickly rollback to the previous version is essential.

Canary Deployment Strategy

This deployment technique in Kubernetes gradually rolls out updates to applications by exposing them to a subset of users or traffic before making them available to the entire user base. Thus, it allows the users to validate the new version’s performance, stability, and user experience in a controlled environment before fully deploying it.

Canary-Deployment

  • The following YAML can be used to implement this kind of deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: my-image:latest
---
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: my-app

Use Case For Canary Deployment Strategy: Canary deployment is useful for applications that want to test new features or changes in a real-world environment before making them available to all users. Thus, we can detect the issues early before the the complete deployment.

A/B Testing Deployment Strategy

The A/B Testing Deployment Strategy compares two or more versions of applications by serving different versions to different subsets of users or traffic. This approach allows users to evaluate performance, usability, and effectiveness of different versions and make data-driven decisions about which version to deploy to entire user base. It is also called as Split Testing.

A_B-Testing

  • The following YAML can be used to implement this kind of deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: my-image:version-a
---
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: my-app

Use Case For A/B Deployment: If you have to experiment with different features, designs, or configurations to optimize user engagement or conversion rates, you can implement the A/B deployment in Kubernetes. Thus, it enhances the performance based on the user-feedback.

Shadow Deployment Strategy

Shadow Deployment in Kubernetes tests new versions or changes to an application in a production-like environment without impacting the existing production workload. It involves running parallel deployment of the new version alongside existing production deployment, allowing users to observe and compare behavior and performance of new version without affecting users or disrupting service.

Shadow-Deployment

  • The following YAML can be used to implement this kind of deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-shadow
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: my-image:latest
---
apiVersion: v1
kind: Service
metadata:
name: my-app-shadow-service
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: my-app

Use Case For Shadow Deployment: Sometimes, we want to validate the behavior and performance of a new version in a real-world scenario before fully deploying it. Hence, Shadow deployment is useful for such cases. It can easily identify differences between the new and existing versions before they impact users.

Conclusion

Kubernetes allows us to containerize and manage software applications in efficient manner. The containers, which are organized into pods(logical units) can be deployed across multiple environments. Different Kubernetes Deployment Strategies allow us to deploy and update applications dynamically with minimal downtime. We have now gained enough insights about Kubernetes and its deployment strategies. Now, we can easily select appropriate Kubernetes deployment strategies as per the requirements.

Kubernetes Deployment Strategies – FAQ’s

What Are The Key Components Of The Kubernetes?

The main components of Kubernetes are Pods that encapsulate the containers, ReplicaSets for pod replication, and Services to provide stable endpoints. It also has Deployments to manage and update the applications, ConfigMaps & Secrets to handle configuration data, and kubernetes Ingress to manage external access in the Kubernetes Environment.

Does Kubernetes Deployment Support Automation?

Kubernetes supports various tools like Helm for package management and Kubernetes Operators for managing complex applications, and CI/CD pipelines. Along with these the Kubernetes APIs also enable the Automation of deployment with Kubernetes.

Is Kubernetes A Part Of DevOps?

Kubernetes supports various new concepts like continuous integration, continuous delivery, and infrastructure as code. All these are aligned with the DevOps Practices and principles for managing containerized applications. Hence, it plays a crucial role in DevOps-based development.

What Is The Difference Between The Docker And Kubernetes?

Docker is primarily a platform for building, packaging, and running containerized applications. It offers tools for creating container images, managing containers, and running them on individual hosts. On the other hand, Kubernetes is a container orchestration platform that automates deployment, scaling, and management of containerized applications across a cluster of machines.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads