- Recreate deployment strategy involves the process of terminating all existing running pods before creating new ones.
- Pod Termination: kubernetes terminates all existing pods.
- Pod Creation: It creates new pods with updated configurations.
| Pro's | Con's |
|---|---|
| Application state entirely renewed | Downtime that depends on the both shutdown and boot duration of the application |
Note
This deployment strategy is suitable for development environment.
-
EC2 Instance with Ubuntu OS
-
Docker installed & Configured
-
Kind Installed
-
Kubectl Installed
-
Kind Cluster running(Use
kind-config.ymlfile present in this directory.)
Note
You have to go inside root dir of this repo and create Kind Cluster using command: kind create cluster --config kind-config.yml --name dep-strg
-
Apply all the manifest files present in the current directory.
kubectl apply -f . -
Run this command to get all resources created in
recreate-nsnamespace.kubectl get all -n recreate-ns
-
Forward the svc port to the EC2 instance port 3000
kubectl port-forward --address 0.0.0.0 svc/recreate-service 3000:3000 -n recreate-ns & -
Open the inbound rule for port 3000 in that EC2 Instance and check the application at URL:
http://<Your_Instance_Public_Ip>:3000
-
Open a new tab of terminal and connect your EC2 instance and run the watch command to monitor the deployment
watch kubectl get pods -n recreate-ns
-
You have successfully accessed the
online_shop with footerwebpage. Now edit the deployment file:recreate-deployment.ymland change the image fromonline_shoptoonline_shop_without_footerand apply.kubectl set image deployment/online-shop online-shop=amitabhdevops/online_shop_without_footer -n recreate-ns kubectl apply -f .
-
or, You can only apply deployment file
kubectl apply -f recreate-deployment.yml
-
Immediately go to second tab where ran watch command and monitor (It will delete all the pods and then create new ones).
-
Deleting Kind Cluster:
kind delete cluster --name dep-strg
Note
If you cannot access the web app after the update, check your terminal — you probably encountered an error like:
error: lost connection to podDon’t worry! This happens because we’re running the cluster locally (e.g., with Kind), and the kubectl port-forward session breaks when the underlying pod is replaced during deployment (especially with Recreate strategy).
🔁 Just run the kubectl port-forward command again to re-establish the connection and access the app in your browser.
✅ This issue won't occur when deploying on managed Kubernetes services like AWS EKS, GKE, or AKS, because in those environments you usually expose services using NodePort, LoadBalancer, or Ingress — not kubectl port-forward.
