A Deployment provides declarative updates for Pods and ReplicaSets.
Deployments add additional capabilities to Pods: rolling updates, rollbacks, ...
Deployments leverage the ReplicaSet objects. They are automatically created when Deployments are created.
ReplicaSet objects provide additional features to Deployments: self-healing and scaling capabilities.
-
Rolling updates (zero-downtime):
When you update Deployment and you post the changes to the API server, Kubernetes creates a new ReplicSet for the Pods (with all the new changes).
While the Deployment is applied, you will notice that two ReplicSets exist for the Deployment:
One with the original changes and a second that reflect the new changes.
For each Pod that is successfully created for the new ReplicaSet, a corresponding one from the old ReplicaSet will be terminated.
Deployments provides settings to control the sequence of time by which Pods will be created (A wait time can be added between Pods creation/termincation).
-
Rollbacks:
When you update Deployment, a new ReplicaSet will be created and new Pods, for this new ReplicaSet, will be created.
The existing Pods of the old ReplicaSet will be terminated, but the old ReplicaSet itself won't be deleted.
If the update is successful, the old ReplicaSet will have no Pod.
If later, you decide to rollback the changes of the new Deployment, the old ReplicaSet will be there and you can perform "easily" the rollback.
-
Self healing:
Self healing is the ability to re-create a Pod if it fails.
-
Scaling:
Scaling is the ability to add delete delete existing Pods. Usually to adjust when the load on the system increases or decreases.
To create/deploy a Deployment, you need first to create a manifest YAML file.
The manifest file describe the Deployment and its components (name, Pods, ...).
You can use kubectl (or any rest client tool) to post the manifest file to the API server
(same behaviour if you use the imperative command to create the Deployment via the "kubectl create" command).
If applicable, the API server verifies that the request is authenticated, validates it's authorized, and runs the admission controllers on it.
The API server verifies the manifest file and, if no issues, it writes a record for that manifest in the cluster store (etcd).
The scheduler will then read the record and deploy the Pod of the Deployment to a healthy worker(s) node(s) with enough available resources.