Declarative deployment pattern¶
The Declarative deployment pattern is a configuration management approach where the user defines the desired state of a system, and the system's controller automatically reconciles the actual state to match the desired state.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]
In the context of Kubernetes, this pattern is implemented via the Deployment resource object. This object manages the deployment of Pods and ReplicaSets by maintaining a declarative definition that ensures the container execution status meets the user's expectations.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]
Key Characteristics¶
The primary characteristic of the declarative pattern is the specification of a desired status. Rather than executing a sequence of commands to build an environment, the user provides a configuration file that describes the target environment.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md] The underlying platform (in this case, the ReplicaSet within Kubernetes) is then responsible for ensuring that resources are created, scaled, or deleted to satisfy this specification.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]
This abstraction allows operators to focus on what the system should look like, rather than how to achieve it.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]
Common Use Cases¶
The declarative deployment pattern supports several critical operational scenarios:
- Defining Deployments: Creating
PodsandReplicaSetsautomatically based on a definition.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md] - Rolling Updates: Updating the Pod specification to a new state. The controller creates a new
ReplicaSetand moves Pods to the new configuration at a controlled rate.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md] - Rollback: Reverting to a previous Deployment revision if the current state is unstable or erroneous.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]
- Scaling: Expanding or contracting the number of Pod replicas to handle load.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]
- Pausing and Resuming: Temporarily stopping a Deployment process.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]
Implementation¶
In a Kubernetes environment, the declarative pattern is typically applied using YAML configuration files and the kubectl apply command.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md] When a configuration is applied, the system checks the current status and makes necessary adjustments.
For example, changing the replicas field in a configuration file and re-applying it triggers the horizontal scaling of the application without the user needing to manually add or remove individual Pods.^[400-devops__06-Kubernetes__k8s-ithelp__Day8__README.md]