Skip to content

Latest commit

 

History

History
executable file
·
170 lines (117 loc) · 6.9 KB

File metadata and controls

executable file
·
170 lines (117 loc) · 6.9 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 and a free cluster will get a memory pressure condition if Istio is installed. If you installed Istio previously, delete it with this command:

$ istioctl manifest generate --set profile=demo | kubectl delete -f -

Note: 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.

1.1 Get the code:

$ git clone https://github.com/IBM/cloud-native-starter.git
$ 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/check-prerequisites.sh

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 $ROOT_FOLDER
$ 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:

IBMCLOUD_API_KEY=AbcD3fg7hIj65klMn9derHHb9zge5
IBM_CLOUD_REGION=us-south
CLUSTER_NAME=cloud-native
REGISTRY_NAMESPACE=cloud-native
IBM_CLOUD_CF_API=https://api.ng.bluemix.net
IBM_CLOUD_CF_ORG=
IBM_CLOUD_CF_SPACE=dev
AUTHORS_DB=local
CLOUDANT_URL=

1.4 Create IBM Kubernetes Service

This step creates a lite Kubernetes cluster on IBM Cloud.

$ sh iks-scripts/create-iks-cluster.sh

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/cluster-config.sh, 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/cluster-get-config.sh

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 retrieves the IKS 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 IKS cluster and you have used other Kubernetes environments before, e.g. Minikube, use this command (cluster-get-config.sh) to get access to the IKS cluster again.

1.5. Create Container Registry

Create a namespace in the IBM Cloud Container Registry:

$ sh iks-scripts/create-registry.sh

If you already ran the IKS non-reactive example, you will already have a Container Registry. In a lite account you have only limited storage for images. It may therefore be necessary to remove the existing repository before creating a new one for the reactive example!

The container images we will build next are stored in the Container Registry as us.icr.io/cloud-native-<randomchars>/<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.

$ cd ${ROOT_FOLDER}
$ sh iks-scripts/deploy-kafka.sh

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/deploy-postgres.sh

3. Deploy and run the reactive sample

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

$ cd ${ROOT_FOLDER}
$ sh iks-scripts/deploy-articles-reactive-postgres.sh
$ sh iks-scripts/deploy-authors.sh
$ sh iks-scripts/deploy-web-api-reactive.sh
$ sh iks-scripts/deploy-web-app-reactive.sh
$ sh iks-scripts/show-urls.sh

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 'show-urls.sh' 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 'show-urls.sh' for the URL.

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

$ cd ${ROOT_FOLDER}
$ sh iks-scripts/deploy-web-api-reactive.sh
$ sh iks-scripts/deploy-articles-reactive-postgres.sh
$ sh iks-scripts/deploy-authors.sh
$ sh iks-scripts/delete-authors.sh
$ sh iks-scripts/delete-articles-reactive.sh

4. Cleanup

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

$ cd ${ROOT_FOLDER}
$ sh iks-scripts/cleanup.sh