Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
169 lines (117 sloc) 6.39 KB

Reactive Java Microservices on IBM Cloud Kubernetes

1. Setup IBM Cloud Kubernetes Service and IBM Cloud Container Registry

If you have already setup the IBM Cloud Cluster with Istio you don’t need to follow the IBM Cloud Cluster setup instructions, because you can use your existing Cluster. You only have to ensure you have deleted the existing Cloud Native Starter services.

If you want to deploy the reactive Cloud Native Starter example on IBM Cloud Kubernetes Service (IKS), the IBM managed Kubernetes offering, then follow these steps. They will create a Kubernetes Lite Cluster and a namespace in the IBM Container Registry (ICR) where the container images of the microservices will be created, stored, and made available for Kubernetes deployments.

Istio is not needed to install in this setup.

A Kubernetes lite cluster itself is free of charge but it can not be created in a IBM Cloud Lite account. In order to create one either a credit card needs to be entered into the IBM Cloud account or you need a promo code which you can sometimes get at conferences where IBM is present. Or contact us.

oc login -u admin -p passw0rd

1.1 Get the code:

$ git clone
$ cd cloud-native-starter/reactive
$ ROOT_FOLDER=$(pwd)

1.2 Prerequisites:

Most important: an IBM Cloud account, you can register for a free account here.

  • git
  • curl
  • docker requires not only the code but also permission to run docker commands
  • kubectl
  • ibmcloud CLI including plugins kubernetes-service and container-registry

Run this script to check the prerequisites:

$ sh iks-scripts/

Important note to non-English users: We use the ibmcloud CLI to set and retrieve configuration information. By default ibmcloud uses the OS environment language as its locale which could lead to errors in some scripts if it is not English. So on non-English systems we advise to set the ibmcloud locale to English by using this command:

$ ibmcloud config --locale en_US

To revert this setting, simply execute:

$ ibmcloud config --locale CLEAR

1.3 To prepare the deployment on IBM Cloud:

This creates an API key for the scripts. The environment information will be stored in the `cloud-native-starter/reactive/local.env' file.

$ ibmcloud login
$ cd ..
$ ibmcloud iam api-key-create cloud-native-starter \
  -d "cloud-native-starter" \
  --file cloud-native-starter.json
$ cat cloud-native-starter.json
$ cp template.local.env local.env 

From the output of cloud-native-starter.json copy the apikey without " " into IBMCLOUD_API_KEY= in file local.env.

The file local.env has preset values for region, cluster name, and image registry namespace in local.env. You can change them of course if you know what you are doing.

Example local.env:


1.4 Create IBM Kubernetes Service

This step creates a lite Kubernetes cluster on IBM Cloud.

$ sh iks-scripts/

Creating a cluster takes some time, typically at least 20 minutes.

The next command checks if the cluster is ready and if it is ready, it retrieves the cluster configuration (which is needed in most of the other scripts), creates file iks-scripts/, and stores the cluster configuration in it. If the cluster isn't ready, the script will tell you. Then just wait a few more minutes and try again.

$ sh iks-scripts/

NOTE: You MUST run this command to check for completion of the cluster provisioning and it must report that the cluster is ready for Istio installation! This command also retrieves the cluster configuration which is needed in other scripts. But this configuration can only be retrieved from a cluster that is in ready state.

From now on if you want to use kubectl commands with your cluster use this command to get access to the cluster:

$ source iks-scripts/

1.5. Create Container Registry

Create a namespace in the IBM Cloud Container Registry:

$ sh iks-scripts/

The container images we will build next are stored in the Container Registry as<imagename>:<tag> if you didn't change the defaults.

2. Install Kafka and Postgres

After every step follow the instructions in the output of the commands to check when the components have been started before moving on.

$ sh iks-scripts/

Note: Postgres will be deployed as a Pod in the free Kubernetes instance. That means the data is lost when the Pod is restarted.

$ sh iks-scripts/

3. Deploy and run the reactive sample

Demo 1: Web application is refreshed automatically when new articles are created

$ sh iks-scripts/
$ sh iks-scripts/
$ sh iks-scripts/
$ sh iks-scripts/
$ sh iks-scripts/

Create a new article either via the API explorer or curl. Open either the web application or only the stream endpoint in a browser. See the output of '' for the URLs.

Demo 2: Test resiliency with reactive REST Endpoint '/articles' in web-api service

Open the API explorer of the web-api service and invoke the '/articles' endpoint. See the output of '' for the URL.

In order to test resiliency, try different combinations of the appliation with and without the articles and authors services being available.

$ sh iks-scripts/
$ sh iks-scripts/
$ sh iks-scripts/
$ sh iks-scripts/
$ sh iks-scripts/

4. Cleanup

To delete all including Kafka and Postgres from Kubernetes, run:

$ sh iks-scripts/
You can’t perform that action at this time.