Deployment lifecycle behavior¶
The deployment lifecycle behavior in Kubernetes defines the actions taken by the system to maintain the desired state of an application, specifically concerning the creation, deletion, and automatic replacement of [[Pods]].
Deployment Creation and Initialization¶
When a Deployment is created, the system immediately initiates the creation of [[Pods]] to match the desired state. For example, executing kubectl create deployment mytomcat --image=tomcat results in a Deployment resource being created, followed by the system provisioning a Pod (e.g., mytomcat-58b8488d44-bmqqc) with a status of ContainerCreating.^[400-devops-06-kubernetes-k8s-learning-04deployment-deployment.md]
Deletion and Cascading Termination¶
Deleting a Deployment resource triggers a cascading termination process. If a user deletes a Deployment using kubectl delete deployment, the controller removes the Deployment resource, and consequently, all associated Pods are terminated and removed from the cluster.^[400-devops-06-kubernetes-k8s-learning-04deployment-deployment.md] This ensures that no orphaned resources remain in the namespace after the Deployment is removed.
Self-Healing Behavior¶
The lifecycle behavior includes a self-healing mechanism for [[Pods]] managed by a Deployment. If a specific Pod is deleted manually—for instance, using kubectl delete pod—the Deployment controller automatically detects the discrepancy between the actual state and the desired state.^[400-devops-06-kubernetes-k8s-learning-04deployment-deployment.md] It immediately creates a new Pod to replace the deleted one, ensuring the application's availability and configuration remain consistent.
Sources¶
400-devops-06-kubernetes-k8s-learning-04deployment-deployment.md