IBM Cloud

Simple books App Project Build and Deploy on IBM Cloud

Simple books App Project Build and Deploy on IBM Cloud</span >

Step 1) Click on Terminal</span >

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

 

Build the books app.</span >

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

 

 

Step 2) its time to do Some work in 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.

 

Step 3) Now updating a books</span >

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

 

Let’s edit the title <h1>books – v1</h1>,</span >

  • change it to include your name. <h1>Lovelake4u books – v1</h1>.</span >
  • and Save File…
  • Build and push the app again using the same tag. This will overwrite the previous image.</span >
  • docker build . -t us.icr.io/$MY_NAMESPACE/books:v1 && docker push us.icr.io/$MY_NAMESPACE/books:v1</span >
  • oc import-image books:v1 –from=us.icr.io/$MY_NAMESPACE/books:v1 –confirm</span >

 

Wait Few Minutes…your website is updating..</span >

Refresh your website… Now your name appear on it.</span >

 

 

Step 4) its time to Delete the books

Delete the books

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

 

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</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
  • 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 books app
  • Click the +Add button
  • Select Dockerfile option.

 

 

Paste this in URL

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

 

 

Context Dir box add this

  • /v2/books

 

Under Container Port, enter

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

 

Topology view,

  • click the books Deployment. I
  • Route location to load the books in the browser.</span >
  • Notice that the header says “books – v2.</span >

 

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

  • Create a Tone Analyzer service instance</span >
  • Go to the IBM Cloud catalog. Click Here</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]

 

 

Run this to get your id name

oc project

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

ibmcloud target -g <resource_group></span >

 

Use the Explorer to edit binding-hack.sh.</span >

 

  • The path to this file is
  • books/v2/binding-hack.sh.
  • You need to insert your OpenShift project where it says <my_project>.</span >

 

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

file path: books/v2/analyzer-deployment.yaml</span >

You need to insert your Container Registry namespace where it says <my_namespace></span >

 

 

Step 7) analyzer Deployment.

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

 

Return to the books in the browser,

  • refresh the page,
  • and submit a new entry.
  • #Screenshot 7
  • add /info at the last of url and take</span >
  • #Screenshot 8
  • You should see your entry appear along with a tone analysis.</span >

 

Autoscale books

  • ckick on Topology
  • click the books Deployment.
  • Then click Actions > Edit Deployment.</span >
  • In the template.spec.containers section,</span >
  • 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.</span >

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

 

Click Create.

if you face any problem.. mention me on comments..</span >