Saturday 8 August 2020

Kubernetes: Application upgrades

 In this post, I am going to explain how can we handle application upgrades.

a.   Deploy the image tomcat:8.5.54-jdk11

b.   Upgrade it to the image tomcat:9-jdk14-openjdk-oracle

c.    Rollback to the previous version of tomcat.

 

Deploy the image tomcat:8.5.54-jdk11

Create a deployment using tomcat image ‘tomcat:8.5.54-jdk11’

$kubectl create deployment tomcat --image=tomcat:8.5.54-jdk11
deployment.apps/tomcat created

Check the pods.

$kubectl get pods
NAME                      READY   STATUS    RESTARTS   AGE
tomcat-6586578cf5-h687q   1/1     Running   0          102s

Expose the service.

$kubectl expose deployment tomcat --type=LoadBalancer --port=8080
service/tomcat exposed

Check the status of the service.

$kubectl get services
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP      10.96.0.1       <none>        443/TCP          13m
tomcat       LoadBalancer   10.108.30.197   <pending>     8080:30602/TCP   2s

Execute the command ‘minikube service tomcat’ to open the service in web browser.

$minikube service tomcat
|-----------|--------|-------------|-----------------------------|
| NAMESPACE |  NAME  | TARGET PORT |             URL             |
|-----------|--------|-------------|-----------------------------|
| default   | tomcat |        8080 | http://192.168.99.100:30602 |
|-----------|--------|-------------|-----------------------------|
🎉  Opening service default/tomcat in default browser...

You can confirm that tomcat server version is 8.5.54.

 

Upgrade it to the image tomcat:9-jdk14-openjdk-oracle

Update the image by executing below command.

kubectl set image deployment/tomcat tomcat=tomcat:9-jdk14-openjdk-oracle

$kubectl set image deployment/tomcat tomcat=tomcat:9-jdk14-openjdk-oracle
deployment.apps/tomcat image updated

Since we upgraded to new image, you can see two result sets.

$kubectl get rs
NAME                DESIRED   CURRENT   READY   AGE
tomcat-6586578cf5   1         1         1       21m
tomcat-6746995784   1         1         0       20s

Get the pods.

$kubectl get pods
NAME                      READY   STATUS              RESTARTS   AGE
tomcat-6586578cf5-h687q   1/1     Running             0          22m
tomcat-6746995784-tmvnl   0/1     ContainerCreating   0          60s

As you see the output, pod is in ‘ContainerCreating’ state.

 

Wait for some time and query for the pods again.

$kubectl get pods
NAME                      READY   STATUS    RESTARTS   AGE
tomcat-6746995784-tmvnl   1/1     Running   0          114s

As you see the output, tomcat is in Running state now.

 

Let’s open the service in browser.

$minikube service tomcat
|-----------|--------|-------------|-----------------------------|
| NAMESPACE |  NAME  | TARGET PORT |             URL             |
|-----------|--------|-------------|-----------------------------|
| default   | tomcat |        8080 | http://192.168.99.100:30602 |
|-----------|--------|-------------|-----------------------------|
🎉  Opening service default/tomcat in default browser...


From the above image, you can confirm that tomcat is upgraded to 9.0.34.

 

Rollback to previous version

Execute below command to rollout.

kubectl rollout undo deployment/tomcat

$kubectl rollout undo deployment/tomcat
deployment.apps/tomcat rolled back




Previous                                                    Next                                                    Home

No comments:

Post a Comment