This demo modernizes an existing Java web application (JPetStore) by:
- building Docker containers from the legacy stack.
- moving the app to Azure Kubernetes Service.
Follow the below steps to create resources used in this demo. You will create a Kubernetes cluster.
- Create azure database for mysql servers and note down username, servername and password.
- Create kubernetes service from MCMP Store or from azure portal.
- Follow the instructions in the Access tab of your cluster to gain access to your cluster using kubectl.
To manually deploy the demo, follow the below steps.
Clone the demo repository:
git clone https://github.ibm.com/mcmp-demo/jpetstore-kubernetes.git
cd jpetstore-kubernetes
Folder | Description |
---|---|
jpetstore | Traditional Java JPetStore application |
helm | Helm charts for templated Kubernetes deployments |
pet-images | Pet images (which can be used for the demo) |
Next, use the kubectl
command to allow your Kubernetes cluster access to the secrets you just created.
Encode mysql server secrets using base64, put the same in secrets.yaml file and run the following command.
cd jpetstore
kubectl apply -f secrets.yaml
The docker images for each of the micro-services need to be built and then pushed to a container registry. Here are the steps for pushing to your private registry, but be aware that you could also push them to a public registry.
-
Add secrets related to repository into values.yaml
-
Build and push jpetstoredb image. Run these commands as they are.
# from the jpetstore-kubernetes directory cd db docker build . -t ${MYREGISTRY}/${MYNAMESPACE}/jpetstoredb docker push ${MYREGISTRY}/${MYNAMESPACE}/jpetstoredb
-
Build and push the jpetstoreweb image. Run these commands as they are. You do not need to replace any of the values belwo:
# from the jpetstore-kubernetes directory cd jpetstore docker build . -t ${MYREGISTRY}/${MYNAMESPACE}/jpetstoreweb docker push ${MYREGISTRY}/${MYNAMESPACE}/jpetstoreweb
-
Finally make sure that both images have been successfully pushed to the container registry.
There are two different ways to deploy the three micro-services to a Kubernetes cluster:
- Using Helm to provide values for templated charts (recommended)
- Or, updating yaml files with the right values and then running
kubectl create
For this option, you need to update the YAML files to point to your registry namespace.
kubectl apply -f mysqlJob.yaml
- This creates predefined schema into mysql database.kubectl create -f jpetstore.yaml
- This creates the JPetstore app microservice
Copy the external ip under jpetstore service and try to open it in browser.
You are now ready to use the UI to shop for a pet or query the store by sending it a picture of what you're looking at:
-
Access the java jpetstore application web UI for JPetstore using IP provided by
kubectl get svc -n <namespace>
# Use "helm delete" to delete the two apps
kubectl delete -f jpetstore.yaml
# Delete the secrets stored in our cluster
kubectl delete secret mysql-creds