Deployment: Let the application never go down

"Deployment", as the name suggests, is specially used to deploy applications, which can keep applications from going down and is mostly used to release stateless applications. It is the most commonly used and useful object in Kubernetes.

Key fields of Deployment: first look at the replicas field. Its meaning is relatively simple and clear, which means "number of replicas", that is, specify how many Pod instances to run in the Kubernetes cluster.

Another key field, selector, is used to "screen out" the Pod objects to be managed by the Deployment. The subordinate field "matchLabels" defines the label that the Pod object should carry, and it must match the "labels" defined by the Pod in "template". It is exactly the same, otherwise the Deployment will not be able to find the Pod object to control, and the apiserver will also tell you that the YAML format validation error cannot be created.

The use of this selector field seems a bit redundant at first glance. In order to ensure the successful creation of the Deployment, we must repeat the label twice in the YAML: once in "selector.matchLabels" and another time in "template.matadata".

Kubernetes adopts this "labeling" method. By adding various labels (labels) to the "metadata" meta-information of API objects, we can use a method similar to query statements in relational databases to filter out those with specific identifiers. object. Through the label design, Kubernetes breaks the strong binding between the Deployment and the Pod in the template, turning the composition relationship into a "weak reference".

 Different colors are used to distinguish the fields in the Deployment YAML, and the connection between matchLabels and labels is specially marked with a dotted line.

After the Deployment is successfully deployed, you can also adjust the number of Pods at any time to achieve the so-called "application scaling". This work was very difficult for operation and maintenance before the advent of Kubernetes, but now it becomes easy because of Deployment.

kubectl scale is a command specially used to realize "expansion" and "reduction". You only need to specify the required number of replicas with the parameter --replicas, and Kubernetes will automatically add or delete Pods, so that the final number of Pods can reach the "desired state" .

This article is a study note for Day 15 in July. The content comes from Geek Time "Kubernetes Introductory Practical Course". This course is recommended.

おすすめ

転載: blog.csdn.net/key_3_feng/article/details/131743081