DEV Community

Cover image for Rolling update in Kubernetes
ahmad bayhaqi
ahmad bayhaqi

Posted on

Rolling update in Kubernetes

Rolling Update is a way of updating your application running in Kubernetes without causing downtime. It gradually replaces the old version with the new version one by one, so that users can still access the application while the update is happening. This makes updates more reliable and easier to manage, and helps ensure that your application remains available and responsive to users.

Step 1 -- Create deployment and Service

create file named rolling-app.yaml

cat > rolling-app.yaml << EOF apiVersion: apps/v1 kind: Deployment metadata: name: my-app namespace: rolling spec: replicas: 5 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: nginx image: bayhaqisptr/nginx-canary:v1 ports: - name: http containerPort: 80 resources: requests: cpu: 100m memory: 50Mi limits: cpu: 200m memory: 100Mi --- apiVersion: v1 kind: Service metadata: name: my-app namespace: rolling labels: app: my-app spec: type: NodePort ports: - name: http port: 80 targetPort: http selector: app: my-app EOF 
Enter fullscreen mode Exit fullscreen mode

Create namespace rolling

kubectl create ns rolling 
Enter fullscreen mode Exit fullscreen mode

and apply rolling-app.yaml

kubectl apply -f rolling-app.yaml 
Enter fullscreen mode Exit fullscreen mode

Step 2 -- Set image with another version tag

use command kubectl set image to set image in existing deployment

kubectl set image deployment.v1.apps/my-app my-app=bayhaqisptr/nginx-canary:v2 
Enter fullscreen mode Exit fullscreen mode

see rollout status with following command

kubectl rollout status deployments/my-app 
Enter fullscreen mode Exit fullscreen mode

show available changes that made

➜ rolling kubectl rollout history deployment.apps/my-app -n rolling deployment.apps/my-app REVISION CHANGE-CAUSE 2 <none> 3 <none> 
Enter fullscreen mode Exit fullscreen mode

check service will be responses with version 2

access app with node ip and node port has been created

➜ curl 172.23.0.5:31374 <html> <h1>Hello World!</h1> <p>This is version 2</p> </html> 
Enter fullscreen mode Exit fullscreen mode

Step 3 -- Rollback deployment

rolling back to one previous version

kubectl rolling undo deployment/my-app 
Enter fullscreen mode Exit fullscreen mode

rolling back to specific revisions

kubectl rolling undo deployment/my-app --revision=2 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)