This is a step-by-step tutorial on how to build and deploy this project to the cloud
- Docker
- Java
- Git
- curl
- Maven
- helm. Install helm by following the instructions here
- IBM Cloud CLI (IBM Cloud command line interface)
- kubectl (Kubernetes command line interface)
- DockerHub Account. Click here to create account
- IBM Cloud Account. Click here to create account
- Cloudant Database
- Kubernetes Cluster
If you already have the above pre-requisites, you can jump to Step-by-Step
Steps 0 through 6 shows how to setup IBM Cloud CLI
, kubectl
, Cloudant Database
and your Kubernetes Cluster
0. Make sure you have the accounts highlighted in Pre-Requisites, (i.e. DockerHub and IBM Cloud Account) and install helm.
Note: This instruction assumes you have Mac OSX. Please visit platforms and check your OS equivalent steps to install IBM Cloud CLI for your platform.
curl -fsSL https://clis.cloud.ibm.com/install/osx | sh
ibmcloud plugin install kubernetes-service
git clone https://github.com/cloudreadyapp/hello_cloud_demo.git
cd hello_cloud_demo
ibmcloud login
Note: If there’s an error message: “You are using a federated user ID, please use one time passcode ( ibmcloud login --sso )” use
ibmcloud login --sso
Note: You can create a cluster using the below command, or via the IBM Cloud Dashboard UI. You can only have 1 Lite Kubernetes cluster running at a time. If you already have one, use the existing one or delete it and create a new one.
ibmcloud ks cluster create classic --name hello-cloud-app-cluster
Note: Creating a cluster can take about ~20 minutes. The cluster is ready once its state is normal
.
ibmcloud ks clusters
6.1 First, create an IBM Cloudant instance
Note: Before continuing with the tutorial, make sure you create a server.env
file under database/src/main/liberty/config/server.env
with the appropriate database constants (API Key, Endpoint URL and Database Name) from the Cloudant instance and database you created in step 6.1
cloudantapikey=<cloudant-api-key>
cloudantendpoint=https://<cloudant-end-point>-bluemix.cloudantnosqldb.appdomain.cloud
cloudantdbname=cloud-app
Before proceeding, make sure your cluster is in normal state as highlighted in step 5.1 above
7.0 Make sure you're in the top-level repository directory from step 3, hello_cloud_demo
mvn -f database install
mvn -f database liberty:package
docker pull open-liberty
docker build -t hello-cloud-app database
docker images
docker login
Note: <docker_image_ID>
is obtained from step 9
docker tag <docker_image_ID> <dockerHub_username>/hello-cloud-app:1.0-SNAPSHOT
Note: Replace <dockerHub_username>
with your own DockerHub username
docker push <dockerHub_username>/hello-cloud-app:1.0-SNAPSHOT
From here on, if your cluster is NOT in normal state you'll become -> 🤯 check step 5.1
Note: Your cluster needs to be in the normal state for you to proceed. If you cluster is in deploying
or pending
state, it means that your cluster is still being created.
ibmcloud ks cluster config --cluster hello-cloud-app-cluster
kubectl get nodes
helm repo add ibm-charts https://raw.githubusercontent.com/IBM/charts/master/repo/stable/
Note: Replace <dockerHub_username>
with your own DockerHub username
helm install hello-cloud-app \
--set image.repository=docker.io/<dockerHub_username>/hello-cloud-app \
--set image.tag=1.0-SNAPSHOT \
--set image.pullSecret=default-us-icr-io \
--set service.name=hello-cloud-app-service \
--set service.port=9080 \
--set service.targetPort=9080 \
--set ssl.enabled=false \
ibm-charts/ibm-open-liberty
ibmcloud ks workers --cluster hello-cloud-app-cluster
kubectl get service hello-cloud-app-service -o jsonpath="{.spec.ports[0].nodePort}{'\n'}"
18. Let's access it! <publicIP>
was obtained in step 16 and <port#>
was obtained in step 17 (previous step)
http://<publicIP>:<port#>/HelloCloudDemoProject
You have just built and deployed a backend that can be leveraged by frontend apps -- in our example code, we've included a simple frontend as a basic demo.
19. Follow steps 7 through 12, but make sure that on step 10.1 and step 11 you change the tag. Instead of using 1.0-SNAPSHOT
use 1.1-SNAPSHOT
or 2.0-SNAPSHOT
for example:
docker tag <docker_image_ID> <dockerHub_username>/hello-cloud-app:2.0-SNAPSHOT
docker push <dockerHub_username>/hello-cloud-app:2.0-SNAPSHOT
sudo helm upgrade hello-cloud-app \
--set image.repository=docker.io/<dockerHub_username>/hello-cloud-app \
--set image.tag=2.0-SNAPSHOT \
--set image.pullSecret=default-us-icr-io \
--set service.name=hello-cloud-app-service \
--set service.port=9080 \
--set service.targetPort=9080 \
--set ssl.enabled=false \
ibm-charts/ibm-open-liberty