Deployments in Kubernetes
A Kubernetes Deployment informs Kubernetes on how to create or modify pod instances that host containerized applications.
ReplicaSets wrapped in a Kubernetes wrapper make up Kubernetes deployments. When performing regular functions, the Deployment will manage a single ReplicaSet. It ensures that the number of pods that are required is running. You should not have direct control over the ReplicaSet that the Deployment generates when using Deployments.
All ReplicaSet operations should be performed on the Deployment, managing the ReplicaSet update process.
Deployments automate the launch of pod instances and guarantee that they run as expected across the cluster’s nodes. Faster deployments with fewer failures are the result of increased automation.
Prerequisites:
You will have to determine your operating system version to stop a Kubernetes deployment. In our case, the kubectl instructions are implemented using the Ubuntu 20.04 operating system. You will need to install the Minikube cluster on your system in order to run Kubernetes on Linux.
How to Stop a Deployment?
With the following commands or instructions, you can learn how to stop a deployment in Kubernetes.
Start Minikube
You must first install the Minikube cluster before proceeding to Ubuntu 20.04. To run the commands, open a terminal. To accomplish this, use the keyboard shortcut “Ctrl+Alt+T.” You can also type the command “start minikube” in the terminal. After then, wait a while for it to begin. The image below is the result of the execution of the ‘minikube start’ command:
Create a Deployment
Deployments are generated in Kubernetes by defining all the requirements in a YAML definition file.
To demonstrate how a rolling update deployment is configured, use the following deployment titled deployment.yaml with the following parameters. You can find the entire configuration file here.
The code above builds a ReplicaSet to bring up three Pods [replicas:3]. The.metadata.name column in the example code indicates that a Deployment named nginx-deployment was created. The Deployment generates three replicated Pods according to the.spec.replicas property.
The Deployment’s.spec.selector field explains how it chooses which Pods to handle. In this scenario, you’ll pick a label by making use of the Pod template (app: nginx). If the Pod template meets the criteria, more elaborate selection rules are available.
After configuring the deployment YAML, run the following command to create the deployment. After the command, you can see the message ‘deployment.apps/nginx-deployment created.’
To confirm if the Deployment was created, use the kubectl get deployments command, as shown below. Yes, the deployment is created as it is confirmed by the output.
In order to check the rollout status, write the following command, which mentions the name of the deployment as well.
If there are any ongoing deployments, you can use this command to keep track of their progress. Run ‘kubectl get deployments’ again after a few seconds to see the information.
The ‘kubectl get rs’ command can be utilized here to check the ReplicaSet (rs) that is established by the Deployment. This is the end outcome that you can see below.
To see the labels that are automatically provided for individual Pods, run kubectl get pods —show-labels. This is what the result of the given code might look like (see below):
Pause a Rollout of a Deployment
You can pause a Deployment in Kubernetes. After that, you can make modifications to the Deployment and restart it. To make a modification, deployments do not need to be interrupted. Use the pause command to put a Deployment on hold while you make multiple adjustments.
When you update a Deployment or expect to update it in the future, you can delay rollouts before initiating one or more updates. When you are ready to implement the adjustments, you resume the Deployment’s rollouts. This method allows you to apply several patches in the time between pausing and resuming without having to worry about causing needless rollouts. Get the Deployment details, for example, for a newly formed Deployment:
Type in the below ‘Kubectl get rs’ command in order to obtain the status of the rollout.
Run the given rollout pause command to pause a specific deployment. The message right after the executed command shows that the deployment is successfully paused.
Another option to stop previous deployments is to use the following method. Execute the get deployment command first in order to get a list of active deployments.
In this method, you can easily verify the details. After that, delete the deployment by writing the given command below, in which you have to mention the accurate name of the deployment.
Conclusion:
The kubectl stop concept has been discussed in this post. This command gently terminates a resource identified by its name or filename. The stop command has been deprecated, and the delete command now performs all of its functions. The kubectl delete command tries to gracefully terminate a resource by shutting it down and deleting it. Before deletion, if the resource is scalable, it will be scaled to zero.
In addition to that, we have also mentioned pausing a deployment so that you can easily make changes. For your convenience, we have elaborated on these ideas in great detail.