Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the operation of Deployment

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article is to share with you about how to understand the operation of Deployment, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

We use some simple examples to demonstrate the creation, view, update, delete and other operations of Deployment, in order to quickly grasp the use of Deployment.

Create

First, let's save the following configuration to a file named deployment.yaml.

ApiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deployment labels: app: nginxspec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginxspec: containers:-name: nginx image: nginx:1.19.0

This configuration creates a Deployment resource object called nginx-deployment, which, according to the information in spec.replicas, expects three copies of Pod.

Next, use the kubectl create command to submit the configuration to kube-apiserver, as follows:

[root@ecs-d8b6 manifests] # kubectl create-f deployment.yaml deployment.apps/nginx-deployment created

According to the command line output, a Deployment named nginx-deployment has been created.

View

When you create a Deployment resource object, the Deployment controller does not create the Pod directly, but indirectly creates the Pod by creating the ReplicaSet.

View Deployment

View the newly created Deployment resource:

[root@ecs-d8b6 manifests] # kubectl get deploymentNAME READY UP-TO-DATE AVAILABLE AGEnginx-deployment 3/3 3 3 90s

The meanings of the fields in the command line output are as follows:

NAME:Deployment resource name, same as metadata.name in configuration

READY:/

UP-TO-DATE: the number of Pod in the latest statu

AVAILABLE: number of Pod available

AGE: the running time of the application, which is also the time elapsed since the resource was created.

There are some slight differences between READY and AVAILABLE here. When all the containers specified in Pod are running, the Pod can be identified as READY, so the meaning of READY is more inclined to Running, while AVAILABLE requirements are more stringent. Only when Pod is in the READY state and lasts for a period of time can it be identified as AVAILABLE, which means more inclined to the available quantity.

UP-TO-DATE refers to the number of Pod running the latest configuration. When you modify the Pod template in the Deployment configuration, the new version of Pod will be created and will coexist with the old version of Pod in a short time. UP-TO-DATE represents the number of new versions of Pod that have been created.

View ReplicaSet

Then take a look at ReplicaSet:

[root@ecs-d8b6 manifests] # kubectl get replicasetNAME DESIRED CURRENT READY AGEnginx-deployment-6fd78f555b 3 3 3 104s

The ReplicaSet name created by Deployment consists of the name of the Deployment and a random string.

View Pod

Then take a look at the resulting Pod:

[root@ecs-d8b6 manifests] # kubectl get podsNAME READY STATUS RESTARTS AGEnginx-deployment-6fd78f555b-clf9w 1/1 Running 0 110snginx-deployment-6fd78f555b-vlvp6 1/1 Running 0 110snginx-deployment-6fd78f555b-wjslg 1/1 Running 0 110s

These Pod are automatically created by ReplicaSet, and their names consist of a ReplicaSet name and a random string.

Update

Because the Deployment controller creates and manages the Pod through ReplicaSet, when you modify the spec.replicas in the Deployment configuration, the Deployment controller modifies the spec.replicas value in the Replicaset accordingly, and eventually the Replicaset controller adjusts the number of replicas of the Pod. This part of the function has been demonstrated in the introduction to ReplicaSet, but will not be demonstrated here.

Here we demonstrate a higher-level feature of Deployment than ReplicaSet, that is, the upgrade and downgrade of the application version. The nginx image version used by the current application is 1.19.0, and we want to reduce this version to 1.18.0.

Change the spec.template.spec.containers.image value from nginx:1.19.0 to nginx:1.18.0 with the following command:

[root@ecs-d8b6 manifests] # kubectl edit deployments nginx-deployment

Then look at Deployment, ReplicaSet, and Pod again:

[root@ecs-d8b6 manifests] # kubectl get deploymentNAME READY UP-TO-DATE AVAILABLE AGEnginx-deployment 3/3 33 33m [root@ecs-d8b6 manifests] # kubectl get replicaset NAME DESIRED CURRENT READY AGEnginx-deployment-6fd78f555b 0 0 0 33mnginx-deployment-7df9bc6ff5 33 3 32s [root@ecs-d8b6 manifests] # kubectl get podsNAME READY STATUS RESTARTS AGEnginx-deployment-7df9bc6ff5-4rz8l 1 + 1 Running 0 40snginx-deployment-7df9bc6ff5-tmxwl 1 + 1 Running 0 44snginx-deployment-7df9bc6ff5-vmdzp 1 + + 1 Running 0 42s

As you can see, the previous number of ReplicaSet (nginx-deployment-6fd78f555b) copies has been modified to 0, and a new ReplicaSet (nginx-deployment-7df9bc6ff5) has been created, which in turn has created a new Pod. The container image version running in the new Pod is our modified container image version, which can be verified by readers.

Delete

When you delete a Deployment resource, the ReplicaSet created by the Deployment controller is also deleted, so the Pod created by ReplicaSet is also deleted.

[root@ecs-d8b6 manifests] # kubectl delete deployment nginx-deployment deployment.apps "nginx-deployment" deleted [root@ecs-d8b6 manifests] # kubectl get replicasetNo resources found in default namespace. [root@ecs-d8b6 manifests] # kubectl get podsNo resources found in default namespace. The above is how to understand the operation of Deployment, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report