Deploying the Bookinfo Application

TOC

An Overview of the Bookinfo Application

To install the bookinfo sample application, two primary steps are required: first, deploying the application itself, and second, setting up a gateway to make it accessible from outside the cluster.

The bookinfo application serves as a tool for exploring the features of a service mesh. It allows you to easily verify that web browser requests are correctly routed through the mesh to the application.

The bookinfo application presents information about a book, much like a single entry in an online bookstore's catalog. It shows a page with a book description, its details (such as ISBN and page count), and customer reviews.

When exposed through the mesh, the behavior of the bookinfo application's microservices is governed by the mesh configuration. The review data is sourced from one of three services: reviews-v1, reviews-v2, or reviews-v3. If you deploy bookinfo without a defined reviews virtual service, the mesh defaults to a round-robin policy for routing requests to these services.

By creating a reviews virtual service, you can define custom routing rules. For instance, you could configure the mesh to direct requests to the reviews-v2 service when a user is logged in, which would display reviews with black stars. Conversely, for users who are not logged in, the mesh could route requests to reviews-v3, showing reviews with red stars.

Additional details can be found in the upstream Istio documentation for the Bookinfo Application.

Deploying the Bookinfo Application

Prerequisites

  • Alauda Service Mesh v2 Operator is installed.
  • An Istio CNI is deployed.
  • An Istio control plane is deployed.

Procedure

  1. Use the following command to Create a new namespace named bookinfo:

    kubectl create namespace bookinfo
  2. Enable sidecar injection for the bookinfo namespace. If your setup uses the InPlace upgrade strategy, run this command:

    kubectl label namespace bookinfo istio-injection=enabled
    NOTE

    If you are using the RevisionBased upgrade strategy, execute these commands:

    1. To discover your <revision-name>, run the following:

      kubectl get istiorevisions.sailoperator.io

      Sample output:

      NAME      NAMESPACE      PROFILE   READY   STATUS    IN USE   VERSION   AGE
      default   istio-system             True    Healthy   True     v1.26.3   47h
    2. Label the namespace using the revision name to enable sidecar injection:

      kubectl label namespace bookinfo istio.io/rev=default
  3. Optional : If you have already configured discoverySelectors, use the following command to apply the Istio discovery selector to the bookinfo namespace:

    Example discovery selector label: istio-discovery=enabled

    kubectl label namespace bookinfo istio-discovery=enabled
  4. Deploy the bookinfo application by applying its YAML file with the following command:

    kubectl -n bookinfo apply -f https://raw.githubusercontent.com/istio/istio/refs/heads/master/samples/bookinfo/platform/kube/bookinfo.yaml

Verification

  1. To confirm the bookinfo service is available, run this command:

    kubectl get services -n bookinfo

    Example output

    NAME          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
    details       ClusterIP   10.4.153.200   <none>        9080/TCP   4m44s
    productpage   ClusterIP   10.4.132.101   <none>        9080/TCP   4m43s
    ratings       ClusterIP   10.4.76.104    <none>        9080/TCP   4m44s
    reviews       ClusterIP   10.4.48.38     <none>        9080/TCP   4m44s
  2. To check that the bookinfo pods are available, execute the following command:

    kubectl get pods -n bookinfo

    Example output

    NAME                              READY   STATUS    RESTARTS   AGE
    details-v1-c66556f6d-bbqjx        2/2     Running   0          5m56s
    productpage-v1-5f568ff46d-r886k   2/2     Running   0          5m56s
    ratings-v1-74bcfcb96d-7bm8s       2/2     Running   0          5m56s
    reviews-v1-549bfb5f44-xwh4z       2/2     Running   0          5m56s
    reviews-v2-6486bc9868-snch4       2/2     Running   0          5m56s
    reviews-v3-6c66dc6cdd-87jgd       2/2     Running   0          5m56s

    A successful proxy sidecar injection is indicated when the Ready column shows 2/2. Ensure the Status column for each pod shows Running.

  3. Confirm the bookinfo application is running by sending a request to its product page. Execute this command:

    kubectl exec "$(kubectl get pod -l app=ratings -n bookinfo -o jsonpath='{.items[0].metadata.name}')" -c ratings -n bookinfo -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>"

    Example output

    <title>Simple Bookstore App</title>

Accessing the Bookinfo Application via a Gateway

Gateways are not deployed by the Alauda Service Mesh v2 Operator because they are not considered part of the control plane. For security, it is a best practice to deploy Ingress and Egress gateways in a separate namespace from the control plane.

There are two methods for deploying gateways: using the Gateway API or the gateway injection technique.

Accessing the Bookinfo Application with Istio Gateway Injection

The gateway injection technique leverages the same mechanism as Istio sidecar injection. It creates a gateway from a Deployment resource that is associated with a Service resource. This Service can then be exposed outside the Alauda Container Platform cluster.

Prerequisites

  • Alauda Service Mesh v2 Operator is installed.
  • An Istio control plane is deployed.

Procedure

  1. Execute the following command to create the istio-ingressgateway deployment and service:

    kubectl -n bookinfo apply -f https://raw.githubusercontent.com/alauda-mesh/sail-operator/refs/heads/main/chart/samples/ingress-gateway.yaml
  2. Configure the bookinfo application to use the newly created gateway by running this command:

    kubectl -n bookinfo apply -f https://raw.githubusercontent.com/istio/istio/refs/heads/master/samples/bookinfo/networking/bookinfo-gateway.yaml
    NOTE

    This example uses a sample gateway configuration file to set up gateway injection for the bookinfo application. The file must be applied in the same namespace where the application is installed.

  3. Optional : Modify the YAML file for automatic pod scaling based on ingress traffic.

    Example configuration

    apiVersion: autoscaling/v2
    kind: HorizontalPodAutoscaler
    metadata:
      labels:
        istio: ingressgateway
        release: istio
      name: ingressgatewayhpa
      namespace: bookinfo
    spec:
      minReplicas: 2
      maxReplicas: 5
      metrics:
        - resource:
            name: cpu
            target:
              averageUtilization: 80
              type: Utilization
          type: Resource
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: istio-ingressgateway
    1. In this example, the maximum replica count is set to 5 and the minimum to 2. A new replica is created when CPU utilization hits 80%.
  4. Optional : Define the minimum number of pods that should be running on the node.

    Example configuration

    apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
      labels:
        istio: ingressgateway
        release: istio
      name: ingressgatewaypdb
      namespace: bookinfo
    spec:
      minAvailable: 1
      selector:
        matchLabels:
          istio: ingressgateway
    1. This example configuration makes sure at least one replica is running if a pod is restarted on a different node.

Verification

You will connect to the Bookinfo productpage service through the gateway you just provisioned. To access the gateway, you need to use the kubectl port-forward command:

kubectl -n bookinfo port-forward svc/istio-ingressgateway 9080:80
  • If you run the command locally on your workstation, open http://localhost:9080/productpage in your browser.
  • If you ran the command on a remote host and used --address 0.0.0.0, replace localhost with the remote host's IP or hostname (for example http://<REMOTE_HOST_IP>:9080/productpage)

When you refresh the page several times, you should see different versions of reviews shown in productpage, presented in a round robin style (red stars, black stars, no stars), since we haven't yet used Istio to control the version routing.

Accessing the Bookinfo Application with the Gateway API

With the Kubernetes Gateway API, a gateway is deployed through the creation of a Gateway resource.

Prerequisites

  • Alauda Service Mesh v2 Operator is installed.
  • An Istio control plane is deployed.
  • Your Kubernetes cluster supports external load balancers (i.e., Services of type LoadBalancer)

Procedure

  1. Create and configure a gateway with the Gateway and HTTPRoute resources by executing the command below:

    kubectl -n bookinfo apply -f https://raw.githubusercontent.com/istio/istio/refs/heads/master/samples/bookinfo/gateway-api/bookinfo-gateway.yaml 
    NOTE

    This example uses a sample gateway configuration file to configure a gateway for the bookinfo application via the Gateway API. This file must be applied in the application's namespace.

  2. Ensure the Gateway API service is ready and has an address by running the following command:

    kubectl wait --for=condition=programmed gtw bookinfo-gateway -n bookinfo
  3. Retrieve the host with this command:

    export INGRESS_HOST=$(kubectl get gtw bookinfo-gateway -n bookinfo -o jsonpath='{.status.addresses[0].value}')
  4. Retrieve the port with this command:

    export INGRESS_PORT=$(kubectl get gtw bookinfo-gateway -n bookinfo -o jsonpath='{.spec.listeners[?(@.name=="http")].port}')
  5. Retrieve the gateway URL with this command:

    export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
  6. Get the full URL for the product page by running the following command:

    echo "http://${GATEWAY_URL}/productpage"

Verification

  • Confirm that the productpage is accessible with the curl command:

    curl -s "http://${GATEWAY_URL}/productpage" | grep -o "<title>.*</title>"

    Example output

    <title>Simple Bookstore App</title>
  • Confirm that the productpage is accessible in a web browser.

    Point your browser to http://${GATEWAY_URL}/productpage to view the Bookinfo web page.

    When you refresh the page several times, you should see different versions of reviews shown in productpage, presented in a round robin style (red stars, black stars, no stars), since we haven't yet used Istio to control the version routing.