Skip to content

Recreate Strategy

The Recreate Strategy is one of the deployment options available for the kubernetes-deployment resource object in kubernetes^[400-devops__06-Kubernetes__k8s-ithelp__Day13__README.md]. It functions as a resource lifecycle management technique where the deployment controller orchestrates the replacement of application instances.

Definition

In the Recreate strategy, the system first terminates all currently running instances (Pods) of the previous version before creating new instances for the updated version^[400-devops__06-Kubernetes__k8s-ithelp__Day13__README.md].

This behavior is in contrast to strategies that allow old and new versions to coexist during the transition period^[400-devops__06-Kubernetes__k8s-ithelp__Day13__README.md].

Configuration

To implement this strategy, the spec.strategy.type field in the Deployment manifest must be set to Recreate^[400-devops__06-Kubernetes__k8s-ithelp__Day13__README.md].

spec:
  replicas: 3
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: foo

When this configuration is applied, the kubernetes-deployment controller ensures that all existing Pods associated with the deployment enter the Terminating state^[400-devops__06-Kubernetes__k8s-ithelp__Day13__README.md]. Only after these Pods are fully terminated does the controller proceed to schedule and create the Pods for the new version^[400-devops__06-Kubernetes__k8s-ithelp__Day13__README.md].

Characteristics

The primary characteristic of the Recreate strategy is that it results in a service interruption^[400-devops__06-Kubernetes__k8s-ithelp__Day13__README.md]. The duration of this downtime is determined by the time it takes for the application containers to shut down and for the new containers to start and become ready^[400-devops__06-Kubernetes__k8s-ithelp__Day13__README.md].

Due to this downtime, it is generally not recommended for use in production environments or scenarios where high availability is required^[400-devops__06-Kubernetes__k8s-ithelp__Day13__README.md].

Sources

^[400-devops__06-Kubernetes__k8s-ithelp__Day13__README.md]