In this post, we will look at the deployment options for using the Kubernetes container-orchestration system to deploy containers. We will have learned how to deploy in the Kubernetes cluster in a variety of ways by the end of this article. If you really want to learn more about this topic, keep reading the article. The code can be found in the sections below.

What are Deployments in Kubernetes?

Kubernetes deployments are just ReplicaSets wrapped in a Kubernetes wrapper. Deployment monitors the number of operating pods, whereas the ReplicaSet manages the number of running pods. This allows for rolling updates, pod health checks, and easy rollback of updates.

The Deployment will only hold a single ReplicaSet during normal operations, ensuring that the number of required pods are operating.

You should not manage the ReplicaSet that the Deployment creates directly while utilizing Deployments. All operations conducted on a ReplicaSet should instead be performed on the Deployment, managing the ReplicaSet update process.

The ability to execute rolling updates is one of the key benefits of deployment. Deployments give you a lot of flexibility over rolling updates, allowing you to update your pods’ configuration gradually.

What are the Typical Use Cases for Deployment?

Deployments are commonly used in the following scenarios:

  • To roll out a ReplicaSet, create a Deployment. In the background, the ReplicaSet builds Pods. Check the progress of the deployment to check if it was successful.
  • Update the Deployment’s PodTemplateSpec to reflect the changed condition of the Pods. The Deployment is in charge of managing the controlled transfer of Pods from the old to the new ReplicaSet and forming a new one. With each new ReplicaSet, the Deployment’s revision is updated.
  • Increase the Deployment’s capacity to handle greater traffic.
  • Pause a Deployment’s rollout to make various changes to its PodTemplateSpec, then resume it to begin a new rollout.
  • The Deployment status can be used to determine whether or not a rollout has been successful.
  • Remove any previous ReplicaSets that you no longer require.

Prerequisites:

First, you need to install the Minikube cluster and begin Ubuntu 20.04. Now open a terminal to run the commands. For this purpose, press the shortcut “Ctrl Alt T” on the keyboard.

You can also write the command “start minikube” in the terminal. After this, wait for a while till it starts. The following is the result of this instruction:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image1-13.png" data-lazy- height="120" src="data:image/svg xml,” width=”721″>

How to Create a Deployment?

In Kubernetes, deployments are formed by specifying their requirements in a YAML definition file. Let’s use the example of a deployment named deploy.yaml with the following parameters to see how a rolling update deployment is configured:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image3-10.png" data-lazy- height="28" src="data:image/svg xml,” width=”548″>

The whole configuration file may be found here. To bring up three Pods, the code below creates a ReplicaSet. In the example, the.metadata.name column indicates that a Deployment named nginx-deployment has been created. The Deployment produces three replicated Pods, according to the.spec.replicas attribute.

The Deployment’s.spec.selector field specifies how it determines which Pods to manage. In this case, you’ll use the Pod template to select a label (app: nginx). More complicated selection rules are possible if the Pod template fits the criteria.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image2-11.png" data-lazy- height="409" src="data:image/svg xml,” width=”724″>

To create the deployment, execute the given command after configuring the deployment YAML:

$ kubectl create –f deploy.yaml

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image5-9.png" data-lazy- height="38" src="data:image/svg xml,” width=”680″>

Use the kubectl get deployments command to see if the Deployment was created, as shown below.

$ kubectl get deployments

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image4-9.png" data-lazy- height="58" src="data:image/svg xml,” width=”720″>

If there are any ongoing deployments, you can monitor the rollout status by writing this command.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image7-7.png" data-lazy- height="38" src="data:image/svg xml,” width=”716″>

After a few seconds, run kubectl to get deployments again to see the details.

$ kubectl get deployments

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image6-9.png" data-lazy- height="63" src="data:image/svg xml,” width=”698″>

To inspect the ReplicaSet (rs) created by the Deployment, use the kubectl get rs command. Here is the result.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image9-5.png" data-lazy- height="56" src="data:image/svg xml,” width=”721″>

Run kubectl get pods —show-labels to see the automatically produced labels for each Pod. The output might look like this:

$ kubectl get pods –show-labels

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image8-7.png" data-lazy- height="435" src="data:image/svg xml,” width=”722″>

How to Update a Deployment?

To update your Deployment, follow the steps elaborated below:

Let’s change the nginx Pods to employ the following version of nginx: Instead of using the nginx:1.14.2 image, use the 1.16.1 image.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image12-3.png" data-lazy- height="58" src="data:image/svg xml,” width=”726″>

Run the given command and view the rollout status.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image10-4.png" data-lazy- height="39" src="data:image/svg xml,” width=”729″>

After the rollout is complete, use kubectl to get deployments to see the Deployment. The following is the output:

$ kubectl get deployments

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image11-4.png" data-lazy- height="57" src="data:image/svg xml,” width=”722″>

To retrieve details about your deployment, run the following command:

$ kubectl describe deployments

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image13-3.png" data-lazy- height="383" src="data:image/svg xml,” width=”731″>

Assume you made a mistake when changing the Deployment and typed nginx:1.161 instead of nginx:1.16.1 in the image name:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image14-2.png" data-lazy- height="53" src="data:image/svg xml,” width=”728″>

The rollout becomes stalled. You can check the rollout’s performance here:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image15.png6254e954bc3dc.jpg" data-lazy- height="58" src="data:image/svg xml,” width=”724″>

To stop the above deployment status watch, use Ctrl-C.

What are the Benefits of Rolling Updates?

Rolling updates enable progressive integration of changes, giving you more flexibility and control over your application’s lifespan. The following are some of the advantages of using rolling updates for Kubernetes clusters:

  • There is no downtime because the application’s pod instances are always running, even during an upgrade.
  • Allows developers to test the impact of changes in a production environment without interfering with the user experience.
  • It is a cost-effective deployment technique because it does not require additional resources assigned to the cluster.
  • Complex upgrades can be accomplished effectively by making simple modifications to a deployment file, eliminating the need for time-consuming manual migration of configuration files.

Conclusion:

This post covered the basics of deployments, how rolling updates operate, and a variety of configuration choices for fine-tuning updates and pod scheduling. You should now be able to establish and alter deployments with confidence to achieve the correct state for your application.

About the author

<img alt="" data-lazy-src="https://secure.gravatar.com/avatar/d014e3711df41253029f4d4199698df8?s=112&r=g" data-lazy- height="112" src="data:image/svg xml,” width=”112″>

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content