Deploy Microservices

- Thomas Jungbauer Thomas Jungbauer ( Lastmod: 2024-05-05 ) - 3 min read

The second tutorials explains how to install an example application containing thee microservices. All operations have been successfully tested on OpenShift 4.3.

Introduction

As quickly explained at Issue #1, OpenShift 4.3 and the Service Mesh shall be installed already. At this point you should have all 4 operators installed and ready. The test application used in this scenario is based on Java and contains 3 microservices in the following traffic flow:

Customer ⇒ Preference ⇒ Recomandation

The microservices are the same as used at the Interactive Learning Portal.

Deploy microservices

  1. First lets create a new project for our tests

    oc new-project tutorial
  2. EITHER: Add tutorial to ServiceMeshMemberRoll

Service Mesh 1.1 now supports the object ServiceMember which can created under the application namespace and which automatically configures the ServiceMemberRoll. However, below description still works.

+ OpenShift will auto-inject the sidecar proxy to pods of a namespace, if the namespace is configured in the ServiceMeshMemberRoll object which was created for the operator.

  1. Create the file memberroll.yaml:

    cat <<'EOF' > memberroll.yaml
    apiVersion: maistra.io/v1
    kind: ServiceMeshMemberRoll
    metadata:
      name: default
    spec:
      members:
        - tutorial
    EOF
  2. Add the namespace to the member roll:

    oc apply -f memberroll.yaml -n istio-system
If you already have namespaces configured for ServiceMeshMemberRoll, better modify the object manually. Custom Resource Definitions (CRD) do not like to be modified on the fly (currently?)
  1. OR: Create ServiceMeshMember object: Available since ServiceMesh 1.1

    apiVersion: maistra.io/v1
    kind: ServiceMeshMember
    metadata:
      name: default
      namespace: tutorial
    spec:
      controlPlaneRef:
        name: basic-install
        namespace: istio-system
  2. Download the tutorial application locally

    git clone https://github.com/redhat-developer-demos/istio-tutorial/

Deploy microservice: customer

To deploy the first microservice 2 objects (Deployment and Service) must be created. Moreover, the service will be exposed, since the service customer is our entry point.
Verify ~/istio-tutorial/customer/kubernetes/Deployment.yml to check where the actual image is coming from: quay.io/rhdevelopers/istio-tutorial-customer:v1.1

cd ~/istio-tutorial/customer
oc apply -f kubernetes/Deployment.yml -n tutorial
oc apply -f kubernetes/Service.yml -n tutorial
oc expose service customer

Check if pods are running with two containers:

oc get pods -w

The result should look somehow like this:

NAME                             READY   STATUS    RESTARTS   AGE
customer-6948b8b959-g77bs        2/2     Running   0          52m
If there is only 1 container running, indicated by READY = 1/1, then most likely the ServiceMeshMemberRoll was not updated with the name tutorial or contains a wrong project name.

Deploy microservice: preference

The deployment of the microservice preference is exactly like it is done for customer, except that no service must be exposed:

cd ~/istio-tutorial/preference/
oc apply -f kubernetes/Deployment.yml -n tutorial
oc apply -f kubernetes/Service.yml -n tutorial

Check if pods are running with two containers:

oc get pods -w

The result should look somehow like this:

NAME                                 READY   STATUS    RESTARTS   AGE
customer-6948b8b959-g77bs            2/2     Running   0          4d15h
preference-v1-7fdb89c86b-gkk5g       2/2     Running   0          4d14h

Deploy microservice: recommendation

The deployment of the microservice recommendation is exactly like it is done for preference:

cd ~/istio-tutorial/recommendation/
oc apply -f kubernetes/Deployment.yml -n tutorial
oc apply -f kubernetes/Service.yml -n tutorial

Check if pods are running with two containers:

oc get pods -w

The result should look somehow like this:

NAME                                 READY   STATUS    RESTARTS   AGE
customer-6948b8b959-g77bs            2/2     Running   0          4d15h
preference-v1-7fdb89c86b-gkk5g       2/2     Running   0          4d14h
recommendation-v1-69db8d6c48-p9w2b   2/2     Running   0          4d14h

Optional: build the images

It is possible (and probably a good training) to build the microservices locally to understand how this works. In order to achieve this the packages maven and podman must be installed.

Build customer

Go to the source folder of customer application and build it:

cd ~/projects/istio-tutorial/customer/java/springboot
mvn package

It will take a few seconds, but it should give "BUILD SUCCESS" as output, if everything worked.

Now the image will be built using podman

podman build -t example/customer .

Build preference

The image build process of the second microservice follows the same flow as customer:

cd ~/istio-tutorial/preference/java/springboot
mvn package
podman build -t example/preference:v1 .
the "v1" tag at the image name is important and must be used.

Build recommendation

The image build process of the third microservice follows the same flow as preference:

cd ~/projects/istio-tutorial/recommendation/java/vertx
mvn package
podman build -t example/recommendation:v1 .
the "v1" tag at the image name is important and must be used. Later other versions will be deployed.