IBM Cloud

Project Build and Deploy a Simple Guestbook App

Hello Friends in this article i am gone to share Project Build and Deploy a Simple Guestbook App with you..


Also visit:ย  Create a starter Node js application with a Cloudant DB service


 

Project Build and Deploy a Simple Guestbook App

Final Project

Objectives : In this lab, you will:

  1. Build and deploy a simple guestbook application
  2. Use OpenShift image streams to roll out an update
  3. Deploy a multi-tier version of the guestbook application
  4. Create a Watson Tone Analyzer service instance on IBM Cloud
  5. Bind the Tone Analyzer service instance to your application
  6. Autoscale the guestbook app

Step 1) Click on Terminal

  • Terminal > New Terminal. New terminal
  • cd /home/project
  • git clone https://github.com/ajp-io/guestbook.git
  • cd guestbook
  • ls
  • cd v1/guestbook
  • cat Dockerfile
  • export MY_NAMESPACE=sn-labs-$USERNAME
  • export MY_NAMESPACE=sn-labs-staging-$USERNAME

Build the guestbook app.

  • docker build . -t us.icr.io/$MY_NAMESPACE/guestbook:v1
  • docker push us.icr.io/$MY_NAMESPACE/guestbook:v1
  • ibmcloud cr images
  • oc tag us.icr.io/$MY_NAMESPACE/guestbook:v1 guestbook:v1 –reference-policy=local –scheduled

Step 2) its time to do Some work in OpenShift

  • Open OpenShift
  • Switch to develpoper Mode..
  • Click the +Add button
  • Select container image
  • Select
  • name / image / version
  • and all things leave default —– click create
  • Click on Topology.

Then click the guestbook right menu open drag down you can get your website link.
click and open in new tab.

  • take #Screenshot 1

On The URL bar at last add this /info your guestbook website and

  • take #Screenshot 2

//example = http:// kugdcbio58asdc5154dscuhioad54584a54/info

Step 3) Now updating a guestbook

  • Update the guestbook
  • In IBM virtual lab open File explorer.
  • The path to this file is
  • guestbook/v1/guestbook/public/index.html.
ย 

Let’s edit the title Guestbook – v1,
change it to include your name. <h1>Lovelake4u Guestbook – v1.
and Save File…

Build and push the app again using the same tag. This will overwrite the previous image.

  • docker build . -t us.icr.io/$MY_NAMESPACE/guestbook:v1 && docker push us.icr.io/$MY_NAMESPACE/guestbook:v1
  • oc import-image guestbook:v1 –from=us.icr.io/$MY_NAMESPACE/guestbook:v1 –confirm

Wait Few Minutes…your website is updating..
Refresh your website… Now your name appear on it.
take #Screenshot 3

Switch to the Administrator perspective so that you can view image streams.

  • Click Builds > Image Streams in the navigation.
  • Click the guestbook image stream.
  • Click on History
  • take #Screenshot 4

Return to the Developer perspective.

  • Click on Topology
  • then click on guestbook
  • take #Screenshot 5

Step 4) its time to Delete the guestbook

Delete the guestbook

  • Topology
  • click the guestbook-app application.
  • This is the light gray circle that surrounds the guestbook Deployment.
  • Click Actions > Delete Application.
  • Type in the application name and click Delete.

Step 5) its time to Deploy Redis

Deploy Redis master and slave

  • cd ../../v2
  • cat redis-master-deployment.yaml
  • oc apply -f redis-master-deployment.yaml
  • oc get deployments
  • oc get pods

 

  • cat redis-master-service.yaml
  • oc apply -f redis-master-service.yaml
  • cat redis-slave-deployment.yaml
  • oc apply -f redis-slave-deployment.yaml
  • oc get deployments
  • oc get pods

 

  • cat redis-slave-service.yaml
  • oc apply -f redis-slave-service.yaml

 

Deploy v2 guestbook app

  • Click the +Add button
  • Select Dockerfile option.

Paste this in URL

  • https://github.com/ajp-io/guestbook
  • Click Show Advanced Git Options.

Context Dir box add this

  • /v2/guestbook

Under Container Port, enter

  • 3000
  • leave all things default.
  • Click Create.

Topology view,

  • take #Screenshot 6
  • click the guestbook Deployment. I
  • Route location to load the guestbook in the browser.
  • Notice that the header says “Guestbook – v2.

// when you put some data it will throw error..

//do not take tension…

Step 6) Now we are Creating Tone Analyzer service
Create a Tone Analyzer service instance

  • Go to the IBM Cloud catalog. Click Here
  • login with your ibm account.
  • Search Tone Analyzer
  • Click on it …. select lite version click create..

Get Back to Virtual Lab…

  • ibmcloud login -u [your id]
  • it will ask your password ttpe and verify it
  • after this Set organizatrion
  • ibmcloud target -o [org_name]
  • after this Set space name
  • ibmcloud target -s [space_name]

Run this to get your id name

oc project

 

//Copy id and paste it on <resource_group> it look like 55417815442sdas1asd4

  • ibmcloud target -g <resource_group>

Use the Explorer to edit binding-hack.sh.

The path to this file is

  • guestbook/v2/binding-hack.sh.
  • You need to insert your OpenShift project where it says <my_project>.

After Run This..

  • ./binding-hack.sh

Log back into the lab account.

  • ibmcloud login –apikey $IBMCLOUD_API_KEY
  • cd analyzer
  • docker build . -t us.icr.io/$MY_NAMESPACE/analyzer:v1 && docker push us.icr.io/$MY_NAMESPACE/analyzer:v1
  • cd ..

echo $MY_NAMESPACE
// Copy your namespace…

Use the Explorer to edit this file ( analyzer-deployment.yaml )

file path: guestbook/v2/analyzer-deployment.yaml
You need to insert your Container Registry namespace where it says <my_namespace>

Step 7) analyzer Deployment.
Create the analyzer Deployment.

  • oc apply -f analyzer-deployment.yaml
  • oc apply -f analyzer-service.yaml

Return to the guestbook in the browser,

refresh the page,
and submit a new entry.

  • #Screenshot 7

add /info at the last of url and take

  • #Screenshot 8

You should see your entry appear along with a tone analysis.

Autoscale guestbook

  • ckick on Topology
  • click the guestbook Deployment.
  • Then click Actions > Edit Deployment.
  • In the template.spec.containers section,
  • find resources: {}. Replace that with the following text. Make sure the spacing is correct as YAML uses strict indentation.

resources:

  • limits:
  • cpu: 30m
  • memory: 100Mi
  • requests:
  • cpu: 3m
  • memory: 40Mi
  • Click Save.

Switch to the Administrator perspective.

Switch to Administrator perspective.

  • Select Workloads > Horizontal Pod Autoscalers
  • Click Create Horizontal Pod Autoscaler.
  • Paste the following YAML into the editor.
  • apiVersion: autoscaling/v2beta1
  • kind: HorizontalPodAutoscaler
  • metadata:
  • name: guestbook-hpa
  • spec:
  • scaleTargetRef:
  • apiVersion: apps/v1
  • kind: Deployment
  • name: guestbook
  • minReplicas: 1
  • maxReplicas: 3
  • metrics:
  • – type: Resource
  • resource:
  • name: cpu
  • targetAverageUtilization: 1

Click Create.

Switch to the Administrator perspective so that you can view image streams.

  • Click on Workloads
  • Then Click the Horizontal Pod Autoscalers
  • Click on Overview
  • take #Screenshot 9

if you face any problem.. read official documentation by IBM click here..
Congratulations! You have completed the final project for this course

ย 
ย 
ย