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
Create namespace rolling
kubectl create ns rolling
and apply rolling-app.yaml
kubectl apply -f rolling-app.yaml
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
see rollout status with following command
kubectl rollout status deployments/my-app
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>
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>
Step 3 -- Rollback deployment
rolling back to one previous version
kubectl rolling undo deployment/my-app
rolling back to specific revisions
kubectl rolling undo deployment/my-app --revision=2
Top comments (0)