Skip to content

nerdingitout/oc-scale-update

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 

Repository files navigation

Update and Rollback Deployment with Red Hat OpenShift

Introduction

This tutorial shows you how to deploy, scale, update and rollback your application on Red Hat OpenShift. All of these features are essential to make sure that the developer can deliver their software safely in case of adding new features, updating images, fixing bugs or rolling back an update.

Prerequisites

For this tutorial you will need:

Estimated Time

It will take you around 30 minutes to complete this tutorial.

Steps

Create Application From Existng Docker Image

1- Create a new project using the following command.

oc create namespace guestbook-project

2- Create a new deployment resource using the ibmcom/guestbook:v1 docker image in the project we just created.

oc create deployment myguestbook --image=ibmcom/guestbook:v1

3- This deployment creates the corresponding Pod that's in running state. Use the following command to see the list of pods in your namespace

oc get pods

get pods

4- Expose the deployment on port 3000

oc expose deployment myguestbook --type="NodePort" --port=3000

To view the service we just exposed. Use the following command.

oc get service

get service

Note that the service inside the pod is accessible using the :, but in case of OpenShift on IBM Cloud the NodeIP is not publicly accessible. One can use the built-in kubernetes terminal available in IBM Cloud which spawns a kubernetes shell which is part of the OpenShift cluster network and NodeID:NodePort is accessible from that shell.

5- To make the exposed service publicly accessible, you will need to create a public router. First, go to Networking → Routes from the Administrator Perspective on the web console, then click 'Create Route'.
Fill in the information as follows:

Name:myguestbook
Service:myguestbook
Target Port:3000→3000(TCP)

Then click 'Create', you can leave the rest of the fields empty.

create route
Once created, you will be redirected to 'Route Overview' where you can access the external route from the URL under Location as shown in the screenshot. The Route has been created successfully, and it provides a publicly accessible endpoint URL using which we can access our guestbook application.
If you click on the URL, you will be redirected to a page that looks like the following.
guestbook v1 app
Now that you have successfully deployed the application using existing docker image, you will be learning how to scale and rollback your application

Scale Applications Using Replicas

In this section, you will be scaling applications by creating replicas of the pod you created in the first section. Having multiple replicas of a pod can help you ensure that your deployment has the available resources to handle increasing load on your application.
1- Increase the capacity from a single running instance of guestbook up to 5 instances.

oc scale --replicas=5 deployment/myguestbook

2- Check the status of the deployment

oc rollout status deployment myguestbook

rollout

3- Verify that you have 5 pods running post the oc scale command.

oc get pods -n guestbook-project

get pods rollout pods rollout

Update Application

Red Hat OpenShift allows you to do rolling upgrade of your application to a new container image. This allows you to easily update the running image and to easily undo a rollout if a problem is discovered during or after the deployment. In this section, you will be upgrading the image with v1 tag to a new version with v2 tag.

1- Update your deployment using the v2 image.

oc set image deployment/myguestbook guestbook=ibmcom/guestbook:v2

2- Check the status of the rollout.

oc rollout status deployment/myguestbook

rollout v2

3- Get a list of pods (newly launched) as part of moving to the v2 image.

oc get pods -n guestbook-project

get pods v2

4- Copy the name of one of the new pods and use oc describe pod to confirm that the pod is using the v2 image like the screenshot shown below.

oc describe pod <pod-name>

describe pod Notice that the service and router objects remain unchanged when you changed the underlying docker image version of your Pod.

5- Do a hard refresh on the public router URL to see that the Pod is now using the v2 image of the guestbook application.
guestbook app

Roll back Application

When doing a rollout, you can see references to old replicas and new replicas. In this project, the old replicas are the original 5 pods you deployed in the second section when you scaled the application. The new replicas come from the newly created pods with the new image. All these pods are owned by the deployment. The deployment manages these two sets of pods with a resource called ReplicaSet.

1- To see the guestbook ReplicaSets use the following command.

oc  get replicasets -l app=myguestbook

get replicas
2- Undo your latest rollout using the following command.

oc rollout undo deployment/myguestbook

undo deployment
3- Get the status of undo rollout to see the newly created Pods as part of undoing the rollout.

oc rollout status deployment/myguestbook

rollout success
4- Get the list of the newly created pods as part of undoing the rollout.

oc get pods

rollout get pods
5- Copy the name of one of the pods and use it in the oc describe pod command to view the image and its version used in the pod.

oc describe pod <pod-name>

get pods v1
6- After undoing the rollout, you can check the ReplicaSets and will notice that the old replica set is now active and manages the 5 pods using the following command.

oc get replicasets -l app=myguestbook

get replicas 2
7- To view changes, make sure to hard refresh your browser and pointing and the URL to see if v1 version of the application running.
guestbook v1 app

Summary

In this tutorial, you learned how to deploy an application on Red Hat OpenShift, scale an application using replicas, update the application with new image, and how to rollback your updates.

About

Scale, Update and Rollback your application deployment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published