Stateless Application (Deployment)

It ensures that a specified number of Pod replicas are running at any time and provides declarative update and upgrade capabilities for Pods.

Working Principle

Each Deployment will form the following topological structure with its dependencies. The child nodes in this topological structure are all【stable】, and the deletion of any node will be restarted by the Kubernetes controller.

All Deployment objects are managed by the DeploymentController in the Kubernetes cluster. The DeploymentController will use the Informer to listen to notifications of three different resources when it starts, namely Pods, ReplicaSets, and Deployments. Changes in these three resources will trigger callbacks in the DeploymentController.

Different events will eventually enter the queue held by the controller after being filtered, waiting to be consumed by the worker processes. The following events will trigger:

  1. The synchronization of Deployment;
  2. The changes of Deployment;
  3. The changes of the ReplicaSet related to Deployment;
  4. The deletion event of Pod when the number of Pods related to Deployment is 0;
  5. The DeploymentController will start multiple worker processes when the Run method is called. These worker processes will run the worker method to read the latest Deployment objects from the queue for synchronization.

Implementation Process

  1. The Deployment controller retrieves all Pods carrying the label “app: nginx” from Etcd and then counts their number, which is the actual state.
  2. The value of the Replicas field in the Deployment object represents the desired state.
  3. The Deployment controller compares the two states and then determines whether to create Pods or delete the existing Pods based on the comparison result.
作者:chering  创建时间:2024-12-16 15:55
最后编辑:chering  更新时间:2025-01-17 09:02