Skip to content

Latest commit

 

History

History
228 lines (161 loc) · 10.4 KB

creating-distributed-services.adoc

File metadata and controls

228 lines (161 loc) · 10.4 KB

Creating Distributed Services

In this lab, we’ll install a sample application into the system. This application is included in Istio itself for demonstrating various aspects of it, but the application isn’t tied exclusively to Istio - it’s an ordinary microservice application that could be installed to any OpenShift instance with or without Istio.

The sample application is called Bookinfo, a simple application that displays information about a book, similar to a single catalog entry of an online book store. Displayed on the page is a description of the book, book details (ISBN, number of pages, and so on), and a few book reviews.

The BookInfo application is broken into four separate microservices:

  1. productpage - The productpage microservice calls the details and reviews microservices to populate the page.

  2. details - The details microservice contains book information.

  3. reviews - The reviews microservice contains book reviews. It also calls the ratings microservice to show a ``star'' rating for each book.

  4. ratings - The ratings microservice contains book rating information that accompanies a book review.

There are 3 versions of the reviews microservice:

  1. Version v1 does not call the ratings service.

  2. Version v2 calls the ratings service, and displays each rating as 1 to 5 black stars.

  3. Version v3 calls the ratings service, and displays each rating as 1 to 5 red stars.

The application architecture is described in the below diagram:

Bookinfo Architecture

1. Deploy Bookinfo Application

First, open a new browser with the link:{{ CONSOLE_URL }}[OpenShift web console^]

openshift_login

Login using:

  • Username: {{ USER_ID }}

  • Password: {{ OPENSHIFT_USER_PASSWORD }}

You will see a list of projects to which you have access:

openshift_landing

The project displayed on the landing page depends on which labs you will run today. If you will develop Service Mesh and Identity then you will see pre-created projects as shown in the above screeenshot.

Although your VS Code is running on the Kubernetes cluster, it’s running with a default restricted Service Account that prevents you from creating most resource types. So we’ll log in with your workshop user. Execute the following command in the VS Code terminal:

oc login -u {{ USER_ID }} -p {{ OPENSHIFT_USER_PASSWORD }} https://openshift.default.svc:443

You should see something like this (the project names may be different):

Login successful.

You have access to the following projects and can switch between them with 'oc project <projectname>':

    {{ USER_ID }}-bookinfo
    {{ USER_ID }}-catalog
    {{ USER_ID }}-cloudnative-pipeline
    {{ USER_ID }}-cloudnativeapps
    {{ USER_ID }}-coolstore-dev
  * {{ USER_ID }}-devspaces
    {{ USER_ID }}-inventory
    {{ USER_ID }}-istio-system

Using project "{{ USER_ID }}-devspaces".
ServiceMeshMemberRoll

Before we start depoying our application we need to make sure we have the right access to our different application namespaces. The ServiceMeshControlPlane that includes Elasticsearch, Jaeger, Kiali and Service Mesh Operators, have all been installed at the cluster provisioning time. However for applications to communicate to each other accross different namespaces, we need to ensure that the ServiceMeshMemberRoll is also created.

Let’s create the ServiceMeshMemberRoll

  • Login to the openshift console OpenShift web console

  • Press the plus sign on the right top corner as shown in the picture.

Run yaml in console
  • Select your namespace {{ USER_ID }}-istio-system on the top left; as shown in the picture and paste the below ServiceMeshMemberRoll YAML code into the editor.

apiVersion: maistra.io/v1
kind: ServiceMeshMemberRoll
metadata:
  name: default
  namespace: {{ USER_ID }}-istio-system (1)
spec:
  members:
    - {{ USER_ID }}-bookinfo (2)
    - {{ USER_ID }}-catalog
    - {{ USER_ID }}-inventory
  1. is the istio-system namespace which will hold the ServiceMeshMemberRoll and a bunch of other service mesh related objects.

  2. is the list of projects that will be part of this ServiceMesh; in our case that’s the application spread in three different namespaces/projects.

Click Create. This should create the required ServiceMeshMemberRoll.

Congratulations! Now we have successfully created a ServiceMeshMemberRoll which will cause a new service mesh to be deployed into the {{ USER_ID }}-istio-system project. let’s move on to deploy our application to our service mesh.

Deploying BookInfo App

Open a terminal via VS Code and run the following commands to deploy the bookinfo app:

oc apply -n {{ USER_ID}}-bookinfo -f $PROJECT_SOURCE/istio/bookinfo.yaml

And then create the ingress gateway for the bookinfo:

oc apply -n {{ USER_ID}}-bookinfo -f $PROJECT_SOURCE/istio/bookinfo-gateway.yaml

The above default ingress manages traffic for any incoming host, but we only want it to manage traffic destined to our own ingress, so change the host from * to your specific host with this command:

oc patch -n {{USER_ID}}-bookinfo virtualservice/bookinfo --type='json' -p '[{"op":"add","path":"/spec/hosts","value": ["istio-ingressgateway-{{USER_ID}}-istio-system.{{ROUTE_SUBDOMAIN}}"]}]'

Finally, add default destination rules (we’ll alter this later to affect routing of requests):

oc apply -n {{ USER_ID}}-bookinfo -f $PROJECT_SOURCE/istio/destination-rule-all.yaml

List all available destination rules:

oc get -n {{ USER_ID}}-bookinfo destinationrules

When the app is installed, each Pod will get an additional sidecar container as described earlier.

Add some nice labels to correspond to the different langages/frameworks used in the app:

oc project {{USER_ID}}-bookinfo && \
oc label deployment/productpage-v1 app.openshift.io/runtime=python --overwrite && \
oc label deployment/details-v1 app.openshift.io/runtime=ruby --overwrite && \
oc label deployment/reviews-v1 app.openshift.io/runtime=java --overwrite && \
oc label deployment/reviews-v2 app.openshift.io/runtime=java --overwrite && \
oc label deployment/reviews-v3 app.openshift.io/runtime=java --overwrite && \
oc label deployment/ratings-v1 app.openshift.io/runtime=nodejs --overwrite && \
oc label deployment/details-v1 app.kubernetes.io/part-of=bookinfo --overwrite && \
oc label deployment/productpage-v1 app.kubernetes.io/part-of=bookinfo --overwrite && \
oc label deployment/ratings-v1 app.kubernetes.io/part-of=bookinfo --overwrite && \
oc label deployment/reviews-v1 app.kubernetes.io/part-of=bookinfo --overwrite && \
oc label deployment/reviews-v2 app.kubernetes.io/part-of=bookinfo --overwrite && \
oc label deployment/reviews-v3 app.kubernetes.io/part-of=bookinfo --overwrite && \
oc annotate deployment/productpage-v1 app.openshift.io/connects-to=reviews-v1,reviews-v2,reviews-v3,details-v1 && \
oc annotate deployment/reviews-v2 app.openshift.io/connects-to=ratings-v1 && \
oc annotate deployment/reviews-v3 app.openshift.io/connects-to=ratings-v1

Let’s wait for our application to finish deploying. Go to the {{ CONSOLE_URL }}/topology/ns/{{ USER_ID }}-bookinfo[Topology View^] for the {{USER_ID}}-bookinfo project. You’ll see the app components spinning up:

Bookinfo App

Wait for each component to have the full blue circles, or you can execute the following commands to wait for the deployment to complete and result successfully rolled out:

 oc rollout status -n {{ USER_ID}}-bookinfo -w deployment/productpage-v1 && \
 oc rollout status -n {{ USER_ID}}-bookinfo -w deployment/reviews-v1 && \
 oc rollout status -n {{ USER_ID}}-bookinfo -w deployment/reviews-v2 && \
 oc rollout status -n {{ USER_ID}}-bookinfo -w deployment/reviews-v3 && \
 oc rollout status -n {{ USER_ID}}-bookinfo -w deployment/details-v1 && \
 oc rollout status -n {{ USER_ID}}-bookinfo -w deployment/ratings-v1

Finally, access the http://istio-ingressgateway-{{ USER_ID }}-istio-system.{{ ROUTE_SUBDOMAIN}}/productpage[Bookinfo Product Page^]. It should look something like:

Note

In case you can’t access the product page, please check if your web browser (e.g., Chrome) redirects to the page using HTTPS protocol. You must access the page using HTTP protocol.

Bookinfo App

Reload the page multiple times. The three different versions of the Reviews service show the star ratings differently - v1 shows no stars at all, v2 shows black stars, and v3 shows red stars:

  • v1

no stars
  • v2

black stars
  • v3:

red stars

That’s because there are 3 versions of reviews deployment for our reviews service. Istio’s load-balancer is using a round-robin algorithm to iterate through the 3 instances of this service.

You should now have your OpenShift Pods running and have an Envoy sidecar in each of them alongside the microservice. The microservices are productpage, details, ratings, and reviews. Note that you’ll have three versions of the reviews microservice:

oc get pods -n {{ USER_ID}}-bookinfo --selector app=reviews

The output from the above command should be similar but not the same, since pod names should be different.

NAME                          READY   STATUS    RESTARTS   AGE
reviews-v1-7754bbd88-dm4s5    2/2     Running   0          12m
reviews-v2-69fd995884-qpddl   2/2     Running   0          12m
reviews-v3-5f9d5bbd8-sz29k    2/2     Running   0          12m

Notice that each of the microservices shows 2/2 containers ready for each service (one for the service and one for its sidecar).

Now that we have our application deployed and linked into the Istio service mesh, let’s take a look at the immediate value we can get out of it without touching the application code itself!

Congratulations! You now successfully deployed your first application within your OpenShift Service Mesh. Lets move to the next lab Service Visulization and Montioring