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.

Apply fault injection

  1. Verify that you can successfully send requests to the ratings app from within the mesh.

    Use the kubectl 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 --context ${REMOTE_CONTEXT1} -n bookinfo debug -i pods/$(kubectl get pod --context ${REMOTE_CONTEXT1} -l app=ratings -A -o jsonpath='{.items[0].metadata.name}') --image=curlimages/curl -- curl http://ratings:9080/ratings/1
    

    Example output:

    {"id":1,"ratings":{"Reviewer1":5,"Reviewer2":4}}
    

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

    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 --context $REMOTE_CONTEXT1 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
      

  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 --context $MGMT_CONTEXT -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 --kubecontext $MGMT_CONTEXT
    
  2. Review the Dashboard 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 Resources tab to open the Solo resources page.
    2. In the row for your policy, faultinjection-basic-delay, click View Policy.
    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

You can optionally remove the resources that you set up as part of this guide.
  1. Delete the fault injection policy and testing route table.

    kubectl delete FaultInjectionPolicy faultinjection-basic-delay -n bookinfo --context $MGMT_CONTEXT
    kubectl delete RouteTable ratings-rt -n bookinfo --context $MGMT_CONTEXT
    
  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.