IBM Cloud

Project Build and Deploy a Simple Guestbook App

Project Build and Deploy a Simple Guestbook App

In this article i am gone to share Project Build and Deploy a Simple Guestbook App

 

Final Project

Objectives : In this lab, you will:

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

Step 1) Click on </span ></span >Terminal</span >
</span >

  • Terminal > New Terminal. New terminal</span >

 

  • cd /home/project
  • git clone https://github.com/ajp-io/guestbook.git</span >
  • 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</span >
  • docker push us.icr.io/$MY_NAMESPACE/guestbook:v1</span >
  • 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 </span >OpenShift</span >

  • Open OpenShift
  • Switch to develpoper Mode..
  • Click the +Add button
  • Select container image
  • Select
  • name / image / version
  • and all things leave default —– click create</span >
  • 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
</i >

 

Step 3) Now updating a </span >guestbook</span >

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

Let’s edit the title <h1>Guestbook – v1</h1>,
change it to include your name. <h1>Lovelake4u Guestbook – v1</h1>.
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</span >
  • oc import-image guestbook:v1 –from=us.icr.io/$MY_NAMESPACE/guestbook:v1 –confirm</span >

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.</span >
  • Click the guestbook image stream.</span >
  • 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 </span >the guestbook</span >

Delete the guestbook

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

Step 5) its time to </span >Deploy Redis</span >

Deploy Redis master and slave

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

 

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

 

  • cat redis-slave-service.yaml
  • oc apply -f redis-slave-service.yaml</span >

 

Deploy v2 guestbook app

  • Click the +Add button
  • Select Dockerfile option.

Paste this in URL

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

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</span >
  • Route location to load the guestbook in the browser.
  • Notice that the header says “Guestbook – v2.</span >

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

//do not take tension…

Step 6) Now we are Creating </span > Tone Analyzer service </span >
Create a Tone Analyzer service instance

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

Get Back to Virtual Lab…

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

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></span >

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</span >
  • cd analyzer
  • docker build . -t us.icr.io/$MY_NAMESPACE/analyzer:v1 && docker push us.icr.io/$MY_NAMESPACE/analyzer:v1</span >
  • 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) </span >analyzer Deployment.</span >
Create the analyzer Deployment.

  • oc apply -f analyzer-deployment.yaml</span >
  • oc apply -f analyzer-service.yaml</span >

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</span >

  • ckick on Topology
  • click the guestbook Deployment.
  • Then click Actions > Edit Deployment.</span >
  • 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.</span >

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</span >
  • 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