IBM Cloud

Simple books App Project Build and Deploy on IBM Cloud

In this article i am gone to share Simple books App Project Build and Deploy on IBM Cloud with you..


Also visit:ย  How to Host a Static Website on IBM Cloud


 

Simple books App Project Build and Deploy on IBM Cloud

Step 1) Click on Terminal

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

Build the books app.

  • docker build . -t us.icr.io/$MY_NAMESPACE/books:v1
  • docker push us.icr.io/$MY_NAMESPACE/books:v1
  • ibmcloud cr images
  • oc tag us.icr.io/$MY_NAMESPACE/books:v1
  • books: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.

Step 3) Now updating a books

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

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

  • change it to include your name. <h1>Lovelake4u books – 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/books:v1 && docker push us.icr.io/$MY_NAMESPACE/books:v1
  • oc import-image books:v1 –from=us.icr.io/$MY_NAMESPACE/books:v1 –confirm

Wait Few Minutes…your website is updating..

Refresh your website… Now your name appear on it.

Learn also: How to Create a virtual machine using the GCP command line

 


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.
  • 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 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.
  • Notice that the header says “books – v2.

 

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
  • books/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: books/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 books 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 books

  • ckick on Topology
  • click the books 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: 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..

ย 

ย