This lab illustrates steps to deploy a MicroProfile application, running in a WebSphere Liberty docker container, into a Kubernetes environment, such as IBM Cloud Private, and minikube (bonus).
If you find an issue with the lab instruction you can report it or better yet, submit a PR.
For questions/comments about WebSphere Liberty's docker container or IBM Cloud Private please email Arthur De Magalhaes.
You'll need a few different artifacts to this lab. Check if you have these installed by running:
git --version
mvn --version
java -version
docker --version
helm version
minikube version (bonus)
If any of these is not installed:
- Install a Git client.
- Install Maven.
- Install a Docker engine.
- Install Java 8
- Install helm
- Install minikube (bonus)
This lab has been tested on Mac OSX (High Sierra), Ubuntu 16.04 and Windows 10, but it should work with any OS that supports the above software.
This part of the lab will walk you through the deployment of our sample MicroProfile Application into an IBM Cloud Private cluster, which is built on the open source Kubernetes framework. you'll build a MicroProfile application and package it inside a WebSphere Liberty docker container. You will then utilize a helm chart that deploys the Liberty container in ICP, with the appropriate ingress and service setup, while also deploying and configuring a Cloudant helm chart that stands up the database that holds the data for this microservice.
- You will be provided with a working ICP.
- The
helm
CLI in ICP is protected by TLS, so you need to follow these instructions to setup a protected connected between your machine (client) and the ICP cluster you want to reach. - Once the TLS certificates are in place, you can always go into
Configure client
to copy the commands necessary to configure your local CLI to target the ICP cluster: - We will be using the private docker image registry from ICP, so you'll need to setup the connection so that you can login into that registry later in the lab.
- Clone the project into your machine by running
git clone https://github.com/microservices-api/kubernetes-microprofile-lab.git
- Build the sample microservice by running
cd kubernetes-microprofile-lab/lab-artifacts
and thenmvn clean package
- Build and tag the docker image by using
docker build
and providing a tag that matches your<cluster_CA_domain>/<namespace>/microservice-vote
. As an example, if your<cluster_CA_domain>
ismycluster.icp
and you used thedefault
namespace, then your command would bedocker build -t mycluster.icp:8500/default/microservice-vote
.
We will use IBM Cloud Private's internal docker registry to host our docker image. This allows our image to remain secured on-premises, while being available to your enterprise. You can control which kubernetes namespace they are available under.
- Follow the instruction on this page to
docker login
into the ICP docker registry. Use the credentials you setup during installation (default isadmin/admin
). - Now that you're logged in the registry, you can
docker push
your tagged image (microservice-vote
) into the ICP docker registry. Example:docker push mycluster.icp:8500/default/microservice-vote
- Your image is now available in the ICP registry, which you can verify by going into
Catalog -> Images
.
- Deploy the microservice with the following helm install command
helm install --name=vote helm-chart/microservice-vote --set image.repository=mycluster.icp:8500/default/microservice-vote
. - You can view the status of your deployment by running
kubectl get deployments
. You want to wait until bothmicroservice-vote-deployment
andvote-ibm-cloudant-dev
deployments are available. - Let's check on our deployment. Go into
Workloads -> Deployments
and click on the release name you picked. Click on theEndpoint
link, which brings up the ingress URL. Add/openapi/ui
to the URL to reach the OpenAPI User Interface. For example,https://192.168.99.100/openapi/ui
. - Congratulations, you have successfully deployed a MicroProfile container into a kubernetes cluster! The deployment also included a Cloudant container that is used by our microservice, and an ingress layer to provide connectivity into the API.
The vote
application is using various MicroProfile specifications. The /openapi
endpoint of the application exposes the MicroProfile OpenAPI specification. The /openapi/ui
endpoint is a value-add from Open Liberty, which WebSphere Liberty is based upon. This UI allows developers and API consumers to invoke the API right from the browser!
- Expand the
POST /attendee
endpoint and click theTry it out
button. - Leave the
id
empty, and place your name in thename
field. - Click on the
execute
button. Scroll down and you'll see thecurl
command that was used, theRequested URL
and then details of the response. Copy theid
from theResponse body
. This entry has now been saved into the Cloudant database that our microservice is using. - Now expand the
GET /attendee/{id}
, click theTry it out
button, and paste into the textbox theid
you copied from the previous step. - Click on
execute
and inspect that theRespond body
contains the same name that you created 2 steps ago. You successfully triggered a fetch from our WebSphere Liberty microservice into the Cloudant database. - Feel free to explore the other APIs and play around with the microservice!
- Join the ICP technical community to stay up to date with news related to IBM Cloud Private.
In the bonus section you'll build a MicroProfile application and package it inside a WebSphere Liberty docker container. You will then utilize a helm chart that deploys the Liberty container into a kubernetes cluster (minikube), with the appropriate ingress and service setup, while also deploying and configuring a Cloudant helm chart that stands up the database that holds the data for this microservice.
We will walk you through the deployment of our sample MicroProfile Application into a minikube. You'll notice that we're using the exact same artifacts (helm charts & docker containers) as the steps for ICP. However, minikube is the simplest way for a developer to get a kubernetes cluster up and running locally in their laptop.