Learn about Deployment in Kubernetes

In Kubernetes, the Deployment object is the main object that takes care of deploying and managing our application. It allows us to deploy Pods, update Pods, Pod rollback, and ReplicaSet. How is it in details? Let’s take a look at this tutorial!

The first thing, as I mentioned in the tutorial about the “run” command, is that we can use this command to deploy an application with the syntax as follows:


  • name is the name of this Deployment in Kubernetes after running the “run” command
  • image_name is the name of the Image to be used to run Pod.
  • number_of_replica is the number of Replica of the Pod we need to run the application.
  • port_number is the port we will run this application in Pod.

For example, now I need to run a Deployment to deploy the node-hello application from the image “gcr.io/google-samples/node-hello:1.0”, similar to the one in the tutorial about “run” command but with some more parameters, I will run the following command:


Learn about Deployment in Kubernetes

Check Deployment:

Learn about Deployment in Kubernetes

You can see in the DESIRED column, we have two running Pods for this Deployment.

Check the Pod, you will see the following result:

Learn about Deployment in Kubernetes

On the overview, Deployment will manage the ReplicaSet and the ReplicaSet will manage the Pods to run the application. The Deployment will create ReplicaSet to ensure the number of Pods for our application.

We can also create Deployment in Kubernetes using the YAML spec file.

With the “run” command in the above example, we can rewrite it uses YAML file as follows:

Running the “create” command with the spec file above, you get the same result as above.

When our application is deployed with the Deployment object, it can only access within the cluster.

If you want to check the results of this deployment, you need to login to one of the Pods that are deploying the application. For example, to check the results of the above example, I first need to know the Container ID of Pod with the “docker ps -a” statement:

Learn about Deployment in Kubernetes

then access this Container to check the results:

Learn about Deployment in Kubernetes

As you can see, our application was deployed at port 8080 and the result when accessing this application is “Hello Kubernetes!”.

When our application needs updating, we will need to update the Deployment. Therefore, it is very important to define the strategy to update the Deployment.

Deployment in Kubernetes has 3 parameters defined strategy so that we can update a Deployment.

First, the minReadySecond parameter defines how long a newly created Pod considered as available. By default, Kubernetes will treat Pod available when it runs successfully, so the default value of this parameter is 0.

The 2nd parameter maxSurged defines how many Pods can be increased for this Deployment. The value of this parameter can be any number or in %. By default, this value will be 25% of the number of Pods needed to run your application!

The third parameter relates to how much Pod will become unavailable when Deployment is being updated. The value of this parameter can also be any number or in %. And the default value will also be 25%!

Đánh giá bài viết
Chia sẽ bài viết này ...Share on Facebook
0Tweet about this on Twitter
Share on LinkedIn

Add Comment