Dployment is used to control PODS. If we had used kubectl run mynginx –image=nginx we could have also created a pod with one NGX container, but if we wanted to create 100 pod copies at once, we would use Deployment to create pod copies. Next, I delete the pod I created earlier.

1. Self-healing ability

Kubectl create deployment mytomcat –image=tomcat:8.5.68 Kubectl run mynginx –image=nginx

First the conclusion: Kubectl delete pod name kubectl delete pod name Kubectl create Deployment mytomcat –image=tomcat:8.5.68 create a pod using kubectl create deployment mytomcat –image=tomcat:8.5.68 create a pod using kubectl create deployment mytomcat –image=tomcat:8.5.68 That is to say, a Pod created in Deployment mode has self-healing capability, which is where K8S is very powerful. See below

I first create a pod using Deployment mode, observe that the pod name is the 5hCZs suffix, and then delete the pod.Delete the pod. As you can see, k8S immediately creates a pod with the suffix 6n8vl after I remove the pod. The pod created using Deployment mode will heal itself even if it is removed. With pods created this way, we are not afraid of downtime and application crashes.

2. Multiple copies

Use kubectl create deployment my-dep –image=nginx –replicas=3, replicas=3 to create 3 replicas. My-dep has 3 copies and the container is being createdKubectl get PodView the dashboard

2.1 remove the deploy

Kubectl delete Deployment XXX (XXX = my-dep) does not exist, pod does not exist

2.2 Creating multi-copy applications using visual pages View pod deployment details on nodes kubectl get pod-owideThere are only two working nodes in my cluster, and if there are five working nodes, it is normal for each node to have a POD. If we have 7 working nodes and N2 fails, k8S will create 2 pods on the other two nodes, and the number of pods will still be 5. This is the powerful self-healing capability of K8S

3. Expand and shrink POD capacity

3.1 capacity

Kubectl scale –replicas=5 deployment/my-dep kubectl scale –replicas=5 deployment/my-dep If you look at the result of the actual command execution, you can see that two new pods have been added to the original3.2 shrinkage capacity

After our peak flow has passed, we can also reduce capacityYou can also use kubectl edit deployment my-dep to reduce the size. Using this command will open a ymal file, find replicas TAB and modify it, then exit and save. K8s makes adjustments to the POD, as shown belowK8s can also achieve dynamic capacity expansion, K8S is based on their own applications to determine whether to expand capacity.

4. Pod self-healing and failover 4.1 Self-healing

When the container application in the POD of a node in our cluster runs abnormally (such as OOM), the POD may crash [red part in the figure]. At this time, the K8S cluster will sense the pod crash and try to restart it. If the restart succeeds, the pod will be successfully restarted.After the POD successfully restarts, the cluster is healthy again

4.2 Failover

When one of our nodes is down [the white part in the figure], the POD on the node also crashes. At this time, K8S will transfer the POD on the node to another nodeFor example, move the POD on node 4 to node 3

4.3 Rolling Update

In short, it’s always updating. Look at the picture below, the current application is version V1 [the black part], and the black arrow is the flow of traffic coming, our POD is ready to upgrade to version V2Upgrading to V2 versionThe POD of v2 application is created successfully, turns green, and then the POD of V1 node can be offlineVersion update command: Kubectl set image deployment/my-dep nginx=nginx:1.16.1 –record kubectl rollout status deployment/my-dep Or modify the ymal configuration file with the command kubectl edit Deployment /my-dep

Kubectl rollout history deployment/my-dep — Revision =2 Kubectl rollout undo deployment/my-dep –to-revision=2

5. Summary of workloadIn addition to Deployment, k8s also hasStatefulSetDaemonSetJobAnd other types of resources. We all call itThe workload. Stateful application usageStatefulSetDeployment for stateless applicationsDeploymentThe deployment ofKubernetes. IO/useful/docs/con…