Changes between Initial Version and Version 1 of k8srollingback2023


Ignore:
Timestamp:
Dec 7, 2023, 8:13:00 AM (12 months ago)
Author:
deepthi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • k8srollingback2023

    v1 v1  
     1=== Kubernetes Deployment Strategies: Rolling Updates and Rollbacks ===
     2
     3Kubernetes offers robust deployment strategies, allowing for smooth updates and quick rollbacks in case of issues. The most common strategy is the Rolling Update, which incrementally updates Pods with new ones. Let's dive into how to implement Rolling Updates and Rollbacks.
     4
     5==== Part 1: Rolling Updates ====
     6
     7'''Step 1: Create a Deployment'''
     8
     91. Create a Deployment YAML File: myappdeployment2.yaml
     10
     11{{{
     12apiVersion: apps/v1
     13kind: Deployment
     14metadata:
     15  name: myapp-deployment2
     16spec:
     17  replicas: 3
     18  selector:
     19    matchLabels:
     20      app: myapp2
     21  template:
     22    metadata:
     23      labels:
     24        app: myapp2
     25    spec:
     26      containers:
     27      - name: myapp-container2
     28        image: nginx:1.16
     29        ports:
     30        - containerPort: 80
     31}}}
     32
     33• Deploy it:
     34
     35`kubectl apply -f myappdeployment2.yaml`
     36
     37
     38'''Step 2: Update the Deployment'''
     39
     401. Update the Image: Change the image in your deployment to a new version. For example, update nginx:1.16 to nginx:1.17.
     41
     422. Apply the Updated Deployment:
     43
     44`kubectl apply -f deployment.yaml`
     45
     46• Monitor the Rollout:
     47
     48`kubectl rollout status deployment/myapp-deployment2`
     49
     50Kubernetes will stop the old Pods and start new ones with the updated configuration.
     51
     52'''Step 3: Verify the Update'''
     53
     541. Check the Deployed Pods:
     55
     56`kubectl get pods`
     57
     58You should see the Pods with the new image running.
     59
     60==== Part 2: Rollbacks ====
     61'''
     62Step 1: Trigger a Faulty Update'''
     63
     641. Update the Deployment with a Faulty Image: Change the image to a non-existent or faulty one, like nginx:1.18-faulty.
     65
     662. Apply the Faulty Deployment:
     67
     68`kubectl apply -f deployment.yaml`
     69
     70==== Step 2: Rollback the Update ====
     71
     721. Check the Rollout History:
     73
     74`kubectl rollout history deployment/myapp-deployment`
     75
     76• Rollback to a Previous Revision: Find the revision number you want to rollback to (e.g., 2) and execute:
     77
     78`kubectl rollout undo deployment/myapp-deployment --to-revision=2`
     79
     80• Verify the Rollback:
     81
     82`kubectl get pods`
     83
     84The Pods should be running with the image from the previous stable revision.
     85
     86==== Additional Tips ====
     87
     88• Automated Rollbacks: Set up readiness and liveness probes in your deployment to automatically rollback if the new version fails to start properly.
     89
     90• Canary Deployments: For more controlled updates, consider using canary deployments where only a subset of Pods is updated initially.
     91
     92• Blue/Green Deployments: Another strategy is blue/green deployment, where you deploy a new version alongside the old version and switch traffic once the new version is verified.
     93
     94By mastering these deployment strategies, you can ensure smooth updates and quick recovery in your Kubernetes environment.
     95