In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian for you to introduce in detail "Deployment copy stateless service creation and horizontal expansion method", the content is detailed, the steps are clear, the details are handled properly, I hope this "Deployment copy stateless service creation and horizontal expansion method" article can help you solve your doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.
The words of this article:
Replace (/ r modified ple files /) replace, replace; in this article, the modified yaml file replaces the old yaml file
Rollout (/ recorded ®/) record; in this article is a deploy copy of the record history
Describe (/ d recording skra /) description; in this article, the recording process
Scale (/ ske scaling /) scaling; in this article, the number of scaled copies
Pause (/ p suspend update /); in this article, pause update
Resume (/ r resume zju resume /); in this article, it means to resume from a pause to a normal state
RC (Replication Controller) and RS (ReplicaSet)
(almost deprecated) the RC is the replication controller that ensures that the number of Pod reaches the expected value and that the replica is always available.
(separate use is not recommended) RS is the next generation of RC and supports tag sets.
Stateless service Deployment means stateless. Used to deploy stateless services.
Requests such as web access are stateless. Each request contains all the information you need, and each request has nothing to do with the last time.
Deployment is the most commonly used controller. It is generally used to manage and maintain stateless micro-services within the enterprise, such as configserver, zuul, springboot. You can manage multiple replicas of Pod to achieve seamless migration, automatic expansion and reduction, automatic disaster recovery, one-click rollback and other functions.
The creation of deployment
You can create a Deployment with the command:
Kubectl create deployment nginx-image=nginx:1.20.2
You can generate a yaml file from the copy you create:
Kubectl get deployment nginx-o yaml > nginx.yaml
You can then modify the parameters of the yaml file and reload the new yaml file:
Kubectl replace-f nginx.yaml
You can also modify the yaml file online and take effect directly after you exit:
Kubectl edit deploy nginx
Generate deployment from the yaml file:
ApiVersion: v1itemsannotations-apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "2" creationTimestamp: "2022-02-08T07:52:05Z" generation: 2 labels: app: nginx name: nginx namespace: default resourceVersion: "266395" uid: d4a3dbe9-5156-42cf-aaf5-3dfefccf4753 spec: progressDeadlineSeconds: 600 replicas: 1 # number of copies revisionHistoryLimit: 10 # reserved calendar History version selector: matchLabels: app: nginx strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: app: nginx spec: containers:-image: nginx:1.18.0 imagePullPolicy: Always name: nginx Resources: {} terminationMessagePath: / dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 status: availableReplicas: 1 conditions:-lastTransitionTime: "2022-02-08T07:52:10Z" lastUpdateTime: "2022-02-08T07:52:10Z" message: Deployment has minimum availability. Reason: MinimumReplicasAvailable status: "True" type: Available-lastTransitionTime: "2022-02-08T07:52:05Z" lastUpdateTime: "2022-02-08T07:55:54Z" message: ReplicaSet "nginx-86dddd6686" is progressing Reason: ReplicaSetUpdated status: "True" type: Progressing observedGeneration: 2 readyReplicas: 1 replicas: 2 unavailableReplicas: 1 updatedReplicas: 1kind: Listmetadata: resourceVersion: "" selfLink: ""
Deployment status description:
[root@k8s-master01] # kubectl get deployments.apps-o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTORmynginx 1 Plus 1 1 1 4d5h mynginx nginx k8s-app=mynginx
NAME:Deployment name
The status of READY:Pod, which has reached the number of Ready
UP-TO-DATE: the number of copies that have reached the desired state
AVAILABLE: number of already available
AGE: the time for the program to run
CONTAINERS: custom name of the container
IMAGES: container image name
SELECTOR: managed Pod tags
Upgrade of deployment
Check the version of the image in the deploy that created the nginx: you can see that it is 1.18.0
[root@k8s-master01 ~] # kubectl get deploy-o yaml | grep image-image: nginx:1.18.0 imagePullPolicy: Always
We can use the set command to update the version of the image: the set here means setting.
[root@k8s-master01 ~] # kubectl set image deploy nginx nginx=nginx:1.20.2-- record [root@k8s-master01 ~] # kubectl get deployments.apps nginx-o yaml | grep image kubernetes.io/change-cause: kubectl set image deploy nginx nginx=1.18.1-- record=true-image: nginx:1.20.2 imagePullPolicy: Always
You can view the upgrade process using the following commands:
[root@k8s-master01 ~] # kubectl rollout status deployment nginx [root@k8s-master01 ~] # kubectl describe deployments.apps nginx
The upgrade process is roughly as follows: when you create a deploy, the system will also create a RS for the depoly, and when you update the deploy, the system will add a new RS, and the old RS will be reduced by 1 until the replacement is completed.
Rollback of deployment
The rollback of deployment can be rolled back to the previous version or to the specified version. The number of historical versions is controlled by the following parameter:
RevisionHistoryLimit: 10
Check the historical version: you can see that the copy has changed several times
[root@k8s-master01] # kubectl rollout history deployment nginx deployment.apps/nginx REVISION CHANGE-CAUSE8 kubectl set image deploy nginx nginx=1.18.1-- record=true9 kubectl set image deploy nginx nginx=nginx:1.20.2-- record=true
Roll back to the previous version: undo means undo (my understanding is to undo the current version back to the previous version)
[root@k8s-master01 ~] # kubectl rollout undo deployment nginxdeployment.apps/nginx rolled back
Check that it has been changed from 1.20.2 to 1.18.0:
[root@k8s-master01 ~] # kubectl get deployments.apps nginx-o yaml | grep image kubernetes.io/change-cause: kubectl set image deploy nginx nginx=1.18.1-- record=true-image: nginx:1.18.0 imagePullPolicy: Always
If you release multiple times, roll back to the specified version:
[root@k8s-master01 ~] # kubectl rollout history deployment nginx deployment.apps/nginx REVISION CHANGE-CAUSE9 kubectl set image deploy nginx nginx=nginx:1.20.2-- record=true10 kubectl set image deploy nginx nginx=1.18.1-- record=true you have a new email in / var/spool/mail/root [root@k8s-master01 ~] # kubectl rollout history deployment nginx-- revision=9deployment.apps/nginx with revision # 9Pod Template: Labels: app=nginx pod-template-hash=67d5b4548c Annotations: Kubernetes.io/change-cause: kubectl set image deploy nginx nginx=nginx:1.20.2-- record=true Containers: nginx: Image: nginx:1.20.2 Port: Host Port: Environment: Mounts: Volumes: [root@k8s-master01 ~] # kubectl rollout undo deployment nginx-- to-revision=9deployment.apps/nginx rolled back [root@k8s-master01 ~] # kubectl get deployments.apps nginx-o yaml | grep image kubernetes.io/change-cause: Kubectl set image deploy nginx nginx=nginx:1.20.2-image: nginx:1.20.2 imagePullPolicy: Always
You can see that the version of the above information has been rolled back to version 1.20.2. In addition, even if the update fails and the pull of the new image fails, the old copy will not stop working and will continue to work until the upgrade is successful.
Capacity expansion and reduction of deployment
Use the command to expand the capacity: change the copy of nginx from one to two. Note that the expansion of RS will not change, because the nature of Pod has not changed. The word scale here means zoom.
[root@k8s-master01 ~] # kubectl get deployments.apps NAME READY UP-TO-DATE AVAILABLE AGEnginx 1amp 11 117h [root@k8s-master01 ~] # kubectl scale-- replicas=2 deployment nginx deployment.apps/nginx scaled [root@k8s-master01 ~] # kubectl get deployments.apps NAME READY UP-TO-DATE AVAILABLE AGEnginx 2Accord 22 17hdeployment update pause and resume
Update pause: this command will not take effect immediately after you use the kubectl set command to modify the configuration of Pod after the update is paused. Even if the changes are accumulated many times, they will not take effect immediately.
[root@k8s-master01 ~] # kubectl rollout pause deployment nginx
Pause resume: remove the previous update pause function, and all changes made during the pause will take effect
Attention items of [root@k8s-master01 ~] # kubectl rollout resume deployment nginxdeployment
.spec.historsionHistoryLimit: 10: sets the number of older versions of RS that are retained. If 0, it is not saved.
.spec.minReadySeconds: optional, specifies that the newly created Pod is the minimum number of seconds for Ready without any container crash. The default is 0, which means it is considered available as soon as it is created.
The strategy for rolling updates is to create a new Pod, then delete an old Pod and replace the old one with the new one.
Spec.strategy.type: the way to update deploy. Default is RollingUpdate.
RollingUpdate: scrolling updates, you can specify maxSurge and maxUnavailable
MaxUnavailable: specify the maximum number of Pod that is not available during rollback or update. Default is 25%, or you can set a number. If 0, then maxSurge cannot be 0.
MaxSurge: the maximum number of Pod that can exceed expectations. Optional, default is 25%. If it is 0, then maxUnavailable cannot be 0.
Recreate: rebuild, delete the old Pod first, and then create a new Pod.
Read here, this "Deployment copy stateless service creation and horizontal expansion method" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more about the article, welcome to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.