Apply a policy

Use a fault injection policy to inject a delay to the ratings app. A delay simulates an overloaded upstream service or network issues, and can help you build more resilient apps. Then, you can check out the policy and other Gloo resources in the Gloo UI.

Verify in-cluster routing

Before you apply a policy, verify that the productpage service can route to the ratings-v1 and ratings-v2 services within the same service mesh in cluster1.

  1. In a separate tab in your terminal, open the Bookinfo product page from your local host.

    1. Enable port-forwarding on the product page deployment.
      kubectl -n bookinfo port-forward deployment/productpage-v1 9080:9080
      
    2. Open your browser to http://localhost:9080/productpage?u=normal.
  2. Refresh the page a few times to see the black stars in the Book ratings column appear and disappear. The presence of black stars represents ratings-v2 and the absence of stars represents ratings-v1, and the presence of red stars represents ratings-v3.

Apply fault injection

  1. Create a temporary curl or debug pod and send a request to the ratings app from your local machine. The communication from your local machine to the ratings app is allowed because no access policy is applied yet.

    Create a temporary curl pod in the bookinfo namespace, so that you can test the app setup. You can also use this method in Kubernetes 1.23 or later, but an ephemeral container might be simpler, as shown in the other tab.

    1. Create the curl pod.

      kubectl run -it -n bookinfo curl \
        --image=curlimages/curl:7.73.0 --rm  -- sh
      
    2. Send a request to the ratings app.

      curl http://ratings:9080/ratings/1
      

      Example output:

      {"id":1,"ratings":{"Reviewer1":5,"Reviewer2":4}}
      
    3. Exit the temporary pod. The pod deletes itself.

      exit
      

    Use the kubernetes debug command to create an ephemeral curl container in the deployment. This way, the curl container inherits any permissions from the app that you want to test. If you don't run Kubernetes 1.23 or later, you can deploy a separate curl pod or manually add the curl container as shown in the other tab.

    kubectl -n bookinfo debug -i pods/$(kubectl get pod -l app=ratings -A -o jsonpath='{.items[0].metadata.name}') --image=curlimages/curl -- curl http://ratings:9080/ratings/1
    

    Example output:

    HTTP/1.1 200 OK
    ...
    {"id":1,"ratings":{"Reviewer1":5,"Reviewer2":4}}
    

    If the output has an error about EphemeralContainers, see Ephemeral containers don’t work when testing Bookinfo.

  2. Create a fault injection policy to delay responses from the ratings app by 10 seconds, and a route table specifically for testing access to the ratings app.

    kubectl apply -f- <<EOF
    apiVersion: resilience.policy.gloo.solo.io/v2
    kind: FaultInjectionPolicy
    metadata:
      name: faultinjection-basic-delay
      namespace: bookinfo
    spec:
      applyToRoutes:
        - route:
            labels:
              route: ratings
      config:
        delay:
          fixedDelay: 10s
    ---
    apiVersion: networking.gloo.solo.io/v2
    kind: RouteTable
    metadata:
      name: ratings-rt
      namespace: bookinfo
    spec:
      hosts:
      - ratings
      http:
      - forwardTo:
          destinations:
          - ref:
              name: ratings
              namespace: bookinfo
        labels:
          route: ratings
      workloadSelectors:
      - {}
    EOF
    

  3. Send another request to the ratings app by using the same method as in step 1. Note that this time, the app's response is delayed due to the fault injection.

Launch the Gloo UI

The Gloo UI provides a single pane of glass through which you can observe the status of your service meshes, workloads, and services that run across all of your clusters. You can also view the policies that configure the behavior of your network.

  1. Access the Gloo UI.

    meshctl dashboard
    
  2. Review the Overview page, which presents an at-a-glance look at the health of workspaces and clusters that make up your Gloo setup.

    • In the Workspaces pane, you can review the workspace that was automatically created for you in your Gloo setup.
    • In the Clusters pane, you can review the workload clusters that are currently connected to your Gloo setup.
  3. Verify the details of the fault injection policy that you created in the previous section.

    1. Click the Policies tab to open the Policy Rules page.
    2. Click the name of your policy, faultinjection-basic-delay.
    3. Review the details of the policy, such as the ratings route that it applies to.
    4. Click View YAML.
    5. Scroll to the end of the YAML output to verify that the policy has a state of ACCEPTED.

To learn more about what you can do with the UI, see the Gloo UI guides.

Next

Now that you have Gloo Mesh Enterprise up and running, check out some of the following resources to learn more about Gloo Mesh or try other Gloo Mesh features.

Cleanup

  1. Delete the fault injection policy and testing route table.

    kubectl delete FaultInjectionPolicy faultinjection-basic-delay -n bookinfo
    kubectl delete RouteTable ratings-rt -n bookinfo
    
  2. If you no longer need this quick-start Gloo Mesh environment, you can uninstall Istio resources, sample apps, and Gloo management and agent components by following the steps in Uninstall Gloo Mesh and Istio.