The Wayback Machine - https://web.archive.org/web/20240925233045/https://www.geeksforgeeks.org/kubernetes-deployment/
Open In App

What is Kubernetes Deployment?

Last Updated : 18 Jan, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Kubernetes is an open-source Container Management tool that automates container deployment, container scaling, descaling, and container load balancing (also called as container orchestration tool). It is written in Golang and has a huge community because it was first developed by Google and later donated to CNCF (Cloud Native Computing Foundation). Deployment is an abstraction layer over pods. It is like a blueprint for creating pods. 

Kubernetes Deployment

Kubernetes deployment is a high-level resource object by which you can manage the deployment and scaling of the applications while maintaining the desired state of the application. You can scale the containers with the help of Kubernetes deployment up and down depending on the incoming traffic. If you have performed any rolling updates with the help of deployment and after some time if you find any bugs in it then you can perform rollback also. Kubernetes deployments are deployed with the help of CLI like Kubectl it can be installed on any platform.

Kubernetes Deployment Spec

It mainly consists of three components:

  1. Metadata: It consists of the name and labels for the configuration file. The labels are used for establishing the connection between deployment and services.
  2. Specification: It consists of information regarding the number of replicas, selector labels, and template that is the blueprint for pods. The template itself is like a configuration file for pods and consists of metadata and specification for pods that stores information regarding the containers to be used in the pod, the image to be used for building the container, and the name and ports of the container.
  3. Status: This component is automatically generated and added by Kubernetes. This is the basis of the self-healing feature of Kubernetes. If the desired status and actual status of a deployment do not match Kubernetes fixes the pod and matches it with the desired status.

Kubernetes Deployment YAML

We will be using Minikube to use Kubernetes on our local machine. The Deployment configuration file for Nginx will be:

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 80

Now first open the directory where you have created nginx.yaml file in your terminal and create deployment using the command:

$ kubectl apply -f nginx.yaml

kubectl apply

Now check the status of your deployment if it is ready or not by running the command

$ kubectl get al


Hence we have successfully deployed created a deployment for Nginx.

Updating a Kubernets Deployment

To update a Kubernetes deployment we can simply update its config file using 2 methods:

Method 1: Using the kubectl edit command from the terminal

$ kubectl edit deployment deployment-name



Now you can edit the deployment configuration by pressing “i” for inserting and after editing it you can just press the escape key and then “:wq” to save your changes and exit.

file

Method 2: Updating Configuration Directly

You can open your config file in an IDE like VS Code and edit the config there and apply the config by using the command

$ kubectl apply -f deployment_config.yaml

Let’s say in this case we are updating the container port from 80 to 800.

Rolling Back a Kubernets Deployment

In kubernetes deployment, you can revert back to the previous version of the application if you find any bugs in the present version. It will help you to reduce the problems which are facing by the end users in the current version or updated version of the application.

The following steps can be followed for rolling back a deployment:

Step 1: First list all the revisions by using the following command and select the version of deployment to which you want to roll back.

kubectl rollout history

Step 2: If you want to roll back to the previous version of the deployment you can do that by using the following command. it will roll back the immediate version of deployments.

kubectl rollout undo deployment 
nginx-deployment --to-revision=1 (You can Mention the required version)

Step 3: Reverting back to the previous version of the application will help us to reduce the downtime for the customers It’s crucial to regularly test and validate your rollback process to ensure its effectiveness in real-world scenarios.

Checking the Rollout History of a Kubernets Deployment

Rollout history can be seen by using the following command.

kubectl rollout history <name of the deployment>

This command allows you to view the no.of revisions available in the kubernetes cluster and changes made to them. If you want to see the detailed history of a specific version then you use the following command.

kubectl rollout history deployment/web-appdeployment --revision=3

Rollout history will help you to roll to previous versions of the application if you find bugs or problems in the currently deployed version of the application.

Command to Scale a Kubernets Deployment

Scaling the deployment can be done in many ways we can do it by using the following command.

kubectl scale deployment/tomcat-1stdeployment --replicas= 5

You can do the scaling of the pods with the help of horizontal pod autoscaling by enabling it in the cluster where you chose the required no.of pods to run continuously if there is traffic or not and how many no.of pods should be run while the incoming traffic is increased.

kubectl autoscale deployment/tomcat-1st deployment --min=5 --max=8 --cpu-percent=75

–min= 5 defines how many minimum no.of pods are to be run if there is traffic or not and if there is sudden traffic –max= 8 to how much it can maximize it and it depends upon the –CPU-percent.

Pausing and Resuming a rollout of a Kubernets Deployment

You can pause the deployments which you are updating currently and resume the fallout updates for deployment when you feel that the changes are made correctly you can use the following command to pause the rollouts.

kubectl rollout pause deployment/webapp-deployment

To resume the deployment which is paused you can use the following command.

kubectl rollout resume deployment/webapp-deployment 

When you pause the rollouts you can update the image by using the following command. Then the current version of the deployment will be replaced with the image which we are going to update.

kubectl set image deployment/webapp-deployment webapp=webapp: 2.1

Kubernets Deployment Status

The deployment will pass different stages while it was in deploying. Each stage will say the health of the pods and shows us if any problems are arising.

There are a few deployment statuses as follows which will show the health of the pods there are.

  1. Pending: Deployment is pending representing that it going to start or it is facing some issues to start.
  2. Progressing: Deployment was in progress it was going to be deployed.
  3. Succeeded: Deployment was deployed successfully without any errors or bugs.
  4. Failed: Deployment was not deployed successfully it failed due to some issues.
  5. Unknown: This happens if the kubernetes API is not reached for deployment or the problem with the deployment itself.

Deployment status will help you to monitor the pods and you can take action immediately if you found any trouble or bugs in it.

Progressing Kubernets Deployment

If any deployment is in progress it is meant to be that deployment is in the stage of updating or creating a new replicaset. Following are some of the reasons that deployment is in progress.

  • The deployment is creating for the first time or it was creating a new replicaset.
  • If the deployment is going under the updation or scaling then it will be in progress.
  • The deployment will be in progress when the pods are scaling down or the pod is getting started.

If you want to troubleshoot the deployment then you can use the following command.

kubectl describe deployments

Complete Kubernets Deployment

The following conditions must be satisfied to mark deployment as completed.

  1. All the replicas of the pods must be up and running.
  2. The desired count of pods must match the running count of pods.
  3. All the replicas of the pods which are associated with the deployment must be available.
  4. There must be no single replica of old pods must be running.

To check the status of the pods which are running you can use the following command.

kubectl rollout status <deployment/name of deployment>

Failed Kubernets Deployment

Deployment may fail for several reasons when you try to deploy its newest ReplicaSet it may be in an incomplete position forever. This can cause for different reasons following are the reasons.

  • There is a failure of the readiness probe and liveness probe.
  • Error while pulling the image (Mentioned the wrong tag).
  • There may be insufficient quota while deploying as we mentioned resources.
  • The deployment cannot connect to a dependency, such as a database.

To get more information about the deployment and why is was failed you can use the following command. Which gives you a detailed description of the deployment.

kubectl describe deployments

Kubernets Canary Deployment

The canary deployment will make sure that the deployment is going to content fifty percent of replicas are updated and fifty percent of replicas are older versions the replicas which are updated will be available for some of the end users and based upon their reviews we can replace all the replicas. If the reviews are positive you can update the remaining replicas if the feedbacks are bad then you can roll back to the previous version immediately.

The following are the two approaches to implementing canary deployment.

  1. Splitting the traffic using Istio.
  2. Blue/Green Deployment.

Benefits of Kubernetes Deployments

  • Kubernetes Deployment helps in Container Orchestration that is managing the containers in pods.
  • Enhances microservice architecture.
  • Auto-scaling
  • Automated Rollouts and Rollbacks
  • Load Balancing

Use Cases of Kubernetes Deployments

  • Rollout a ReplicaSet: A Kubernetes deployment generates a replica set a pod that contains information regarding the number of pos to be generated in the background.
  • Declaring a New State of Pods: On updating pod template spec a new replica set is created and deployment moves pods from the old replica set to the new replica set.
  • Scaling: Deployment can be configured to scale up to facilitate more load.
  • Status of Deployment: It can be used to check if the deployment is stuck somewhere by matching the current status with the desired status.
  • Cleaning up old Replica Sets that are no more required.

ReplicaSets vs Deployments

ReplicaSet

Deployments

ReplicaSet will ensure that the desired no.of pods are matching the specified no.of pods as mentioned in the yaml file

Deployment is an advanced replication set that will manage the lifecycle of pods.

ReplicaSet is not suitable for applications that are going to have rolling updates and rollbacks.

Deployment supports the rolling update and rollbacks.

Internally replica set will take care of pods and pods will take care of containers

Internally deployment is going to take care of replica set and the replica set will take care of the pod.

FAQs On Kubernetes Deployment

Is Kubernetes a Container or VM?

Kubenretes is an group virtual machine or nodes and also kubernetes is an container orchestration platform where the master application are deployed in the form of cotainers.

What is a Pod in Kubernetes?

A pod is the smallest unit that exists in Kubernetes. It is similar to that of tokens in C or C++ language. A specific pod can have one or more applications. The nature of Pods is ephemeral this means that in any case if a pod fails then Kubernetes can and will automatically create a new replica/ duplicate of the said pod and continue the operation. The pods have the capacity to include one or more containers based on the requirement. To know more about kubernets pods refer to the kubernetes pods.

Kubernets Deployment Command

You can modify the following command depending on your requirment.

kubectl create deployment <deployment-name> –image=<image-name>

Kubernets Delete Pod

Following is command which is used to delete the kubernets pods.

kubectl delete pod <pod-name>



Previous Article
Next Article

Similar Reads

Kubernetes - Creating Deployment and Services using Helm in Kubernetes
Prerequisite: Kubernetes Helm is used for managing your Kubernetes Deployment. With helm, we can tear down and create a deployment with a single command. we will be creating deployment and services using Helm in Kubernetes. For simplicity, we will be using the nginx image. Deployment of nginx using HelmStep 1: We need to install the Helm. You can i
4 min read
kubernetes Replicaset VS Deployment
In Kubernetes, both Deployment and ReplicaSet are used to manage the lifecycle of pods. In order to Manage the life cycle of applications in a Kubernetes cluster, it relies on both ReplicaSets and Deployments, which are two important components. The emergence of Kubernetes has set it as a dominant platform, delivering dependable solutions for autom
6 min read
What Are The Kubernetes Deployment Stratagies ?
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
9 min read
Java Application Deployment In Kubernetes With Jenkins CI/CD Pipeline
In modern software development, deploying applications to Kubernetes clusters has become a common practice due to their scalability and reliability. Automating this deployment process using continuous integration and continuous deployment (CI/CD) pipelines with Jenkins streamlines the development workflow and ensures consistent, reliable deployment
5 min read
Python Application Deployment In Kubernetes With Jenkins CI/CD Pipeline
In modern software development, deploying applications to Kubernetes clusters has become a common practice due to their scalability and reliability. Automating this deployment process using continuous integration and continuous deployment (CI/CD) pipelines with Jenkins streamlines the development workflow and ensures consistent, reliable deployment
6 min read
What is Kubernetes Blue Green Deployment?
Blue-green deployment is a software deployment strategy that involves running two identical production environments, known as "blue" and "green." At any given time, only one of these environments serves live traffic, while the other remains idle or serves only non-production traffic (e.g., testing or staging). What is Kubernetes?Kubernetes is an op
6 min read
Continuous Deployment to Kubernetes with GitOps
GitOps is the mechanism that a few companies like Google, Lyft, etc., has chosen to manage their workflows with. It is a modern approach to the implementation of mechanisms for sucking CD/CI (Continuous integration / Deployment) as git repositories are the only source of truth for your infrastructure and application code This approach makes the dep
14 min read
Nod.Js Application Deployment in Kubernetes with Jenkins CI/CD Pipeline
As we know in the modern world we use Continuous Integration and Continuous Deployment for fast and and efficient delivery of our application to the market. Here in this Article, we are deep-diving into how Actually we can deploy Nodejs applications on Kubernetes with the help of Jenkins CI/CD. Primary TerminologiesNode.js: This is a free, open-sou
9 min read
Spring Boot Application Deployment in Kubernetes with Jenkins CI/CD Pipeline
As we know in the modern world we use Continuous Integration and Continuous Deployment for fast and and efficient delivery of our application to the market. Here in this Article, we are deep-diving into how we can actually deploy Spring boot applications on Kubernetes with the help of Jenkins CI/CD. Project WorkFlow.java files: These files contain
14 min read
Kubernetes Deployment Strategies
Kubernetes is an open-source container orchestration tool. It helps to provide run and manage the thousands of containerized applications with different deployment environments. It has two main functionalities Auto scaling and Auto healing. One of its key strengths is its flexibility in deployment methodologies, ensuring easy updating and wide avai
8 min read
Kubernetes - Monolithic Architecture of Kubernetes
There is a new way of developing software apps using a microservices architecture. That's when all the buzz around containers and container orchestration has increased but we have been developing and using these large software apps even before most of us were born. So in this article, we will be discussing what is that old software architecture we
7 min read
Why Kubernetes? Benefits of using Kubernetes
The popularity of container orchestration technologies specially Kubernetes comes from its use cases and the problems that it solves. Kubernetes is the most popular container orchestration and is widely used by Cloud Native Computing Foundation (CNCF), the foundation to which Kubernetes as a project was donated by Google, estimates that about 92% b
8 min read
Kubernetes Controller VS Kubernetes Operator
Kubernetes Controllers are ideal for managing stateless apps and maintaining the correct number of copies, but Kubernetes Operators are more appropriate for complicated, stateful applications that require human-like decision-making abilities. Kubernetes ControllerKubernetes Controllers are ideal for managing stateless apps and maintaining the corre
4 min read
Microsoft Azure - Container Registration for App Deployment
In this article, we will learn how to use Azure Container Registry to run a .NET Core App. Azure Container Registry is a place where you can store your container images securely. Let's deploy a container image to it and see how we can use it. To follow along, you'll need the following: Visual StudioDocker Desktop. Here in Visual Studio, we've creat
2 min read
Microsoft Azure - Azure SQL Managed Instance Deployment Options
In this article, we will take a deeper look at the differences between Azure SQL Managed Instance and Azure SQL Database. When you're going to deploy a Managed Instance, you're first going to have some choices to make. You can deploy a single instance, which is like a single instance of SQL Server, get these capabilities of your surface area, of yo
3 min read
Microsoft Azure - Azure SQL Database Deployment Options
Azure SQL Database is a database built for modern Cloud applications. Now coming back to the eccentric concepts for which consider If you have ever worked with Azure SQL Database, you must have come across terms such as "single database" or "Elastic scaling" and so on. There is an increasing trend of building applications in the cloud today. For an
5 min read
Deployment Models in OpenStack
Pre-requisite: OpenStack OpenStack has a set of software tools for providing various cloud computing platforms for public and private clouds. OpenStack is managed by the OpenStack Foundation, a non-profit that oversees both development and community-building around that project. OpenStack is the future of cloud computing backed by some of the bigge
4 min read
ECS Deployment Using Terraform
Pre-requisite: AWS ECS and Terraform ECS (Elastic Container Service) is a fully-managed service offered by AWS (Amazon Web Services) that allows users to run, scale, and manage Docker containers. It provides a highly scalable and secure environment for running containerized applications and integrates with other AWS services such as Elastic Load Ba
4 min read
Google Cloud Deployment Manager
Pre-requisite: Google Cloud Platform Google Cloud Deployment Manager is a tool that helps automate the deployment of resources on the Google Cloud Platform. It works by allowing you to define the desired state of your resources in a YAML configuration file, and then Deployment Manager takes care of creating, updating, and deleting those resources t
6 min read
Django Web Application Deployment On AWS EC2 With Windows Server
In this article, we will study how we can deploy our existing Django web application to Windows Server in AWS EC2. We will also see how to use the public IP of the EC2 instance to access the Django application. For this article, you should have knowledge about setting up EC2 in AWS. So let's proceed with the article. What is Django?Django is a Pyth
4 min read
How to Use AWS Elastic Beanstalk For Scalable Web Application Deployment?
AWS Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS. Benefits of AWS Elastic BeanstalkOffers Quicker Deployment: It offers the simplest way to deploy an application w
5 min read
How To Use AWS CodePipeline For Continuous Integration And Deployment
Continuous integration (CI) and continuous deployment (CD) are essential practices in software development. In continuous integration the system builds the code with every commit to the repository and stores the artifacts into a storage space, further making them available for testing and deployment processes. On the other hand continuous deploymen
9 min read
kuberneets Deployment VS Pod
In the world of modern software development, managing apps may be as difficult as putting together a puzzle without a picture. This is when Kubernetes steps in to save the day! But what is Kubernetes, and why should you care? Let's divide it into bite-sized chunks. Basics of KubernetesThink of Kubernetes as the conductor of an orchestra; however, i
7 min read
Continuous Deployment With AWS Elastic Beanstalk And CodePipeline
In the dynamic domain of software development, orchestrating an obvious DevOps technique is fundamental for upgrading cooperation, speeding up delivery, and ensuring the unwavering quality of applications. One significant part of this methodology is Continuous Deployment (CD), a training that automates the most common way of delivering code changes
8 min read
Deployment Of Spring Boot Application In Jenkins
In this article, we will be exploring how to automate the process of building Spring Boot applications by employing a polling trigger. We will also learn how to generate reports and store artifacts in the process. To achieve this, we will be leveraging the Jenkins server. Our goal is to create a pipeline and write a script that will run every minut
5 min read
Continuous Deployment with Docker Swarm: Automating Container Releases
In software development, specifically for software update and feature addition, it is a very agile world. Continuous Deployment (CD) is crucial and is supported by such practices to automate the frequent delivery of new features and/or updates in coding changes to the production environment with minimal manual involvement. Docker Swarm, a native cl
6 min read
How Raspberry Pi and Kubernetes Work Together?
Pre-requisite: Kubernetes and Raspberry Pi Kubernetes and Raspberry Pi are two popular technologies that can be used together to create powerful and scalable applications. In this article, we will look at what each technology is, how they work together, and the benefits and challenges of using the two technologies together. KubernetesKubernetes is
3 min read
Kubernetes - Kubectl Commands
Pre-requisites: Kubernetes 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. Some basic Kubectl commands in a Kubernetes cluster are as follows: kubectl Commands The most popular kubectl commands and flag
5 min read
Google Cloud Platform - Using Config Sync for Managing Kubernetes
In this article, we will look into how we can manage Kubernetes using Config Sync. To do so let's create a problem statement and resolve the same. Problem Statement: Ravi has a new role, Platform Administrator, and he is tasked with ensuring all the infrastructure created by all of his company's teams is in compliance with governance requirements.
3 min read
Kubernetes - Introduction to Container Orchestration
In this article, we will look into Container Orchestration in Kubernetes. But first, let's explore the trends that gave rise to containers, the need for container orchestration, and how that it has created the space for Kubernetes to rise to dominance and growth. The growth of technology into every aspect of our lives and days has created immense d
4 min read