AWS GameDay Lounge : Chaos Engineering with Gremlin

AWS GameDay Lounge : Chaos Engineering with Gremlin

Pre-Requisites

To successfully complete this course, you’ll need:

  1. A computer with Internet connection
  2. An AWS account supplied at the GameDay Lounge
  3. A Gremlin Pro account supplied by Gremlin

What is Chaos Engineering?

Chaos Engineering is a disciplined approach to identifying failures before they become outages. By proactively testing how a system responds under stress, you can identify and fix failures before they end up in the news.

Chaos Engineering lets you compare what you think will happen to what actually happens in your systems. You literally “break things on purpose” to learn how to build more resilient systems.

If you would like to take a deep dive into learning more about the history and principles, check out this link.

Inject something harmful to build an immunity.

Why do Chaos Engineering?

  • Cost of Downtime

How to do Chaos Engineering?

  • Principles of Chaos Engineering:

    • Plan an experiment
    • Contain the Blast Radius and Magnitude
    • Scale or Squash
  • Terms to know:

    • Blast Radius: The number of hosts and/or containers that are targeted in an experiment.
    • Magnitude: The intensity of the attack you’re running.
    • Abort Conditions: What Conditions Would Cause You to Halt the Experiment?

    • Examples: Error Rate, Latency

    • Big Red Button
- Make sure to Halt the experiment if one of your experiments hits one of the abort conditions
  • Scientific Method:

    • Form a Hypothesis
    • Experiment and Test It
    • Analyze Results
    • Expand Scope and Re-Test
    • Share Results

Today’s Infrastructure and Demo Environment

Today’s demo environment https://github.com/microservices-demo

Getting Set Up

Access AWS Console

  1. Log in via instructions to access AWS console
  2. Click on EKS to confirm there is an EKS cluster. It should have “GremlinGameDay” followed by a string of characters.
  3. Switch over to EC2’s dashboard, and confirm there are 3 instances available for the EKS cluster as well as a bastion host.

Access Monitoring

  1. Open CloudWatch in the AWS Console: http://console.aws.amazon.com/cloudwatch
  2. On the CloudWatch Dashboard, click on Overview and select Container Insights.
  3. Make sure EKS Clusters is selected.

For more information on using Container Insights, see this documentation: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Container-Insights-view-metrics.html

Access Gremlin

  1. Log into gremlin by checking your inbox to complete registration

    1. If you did not get an invite, or receive an error, please ask for support in #aws-gamedaylounge in the Chaos Engineering Slack. Instructions for joining it can be found at https://gremlin.com/slack.
    2. This will open a browser tab to https://app.gremlin.com.

Access your Bastion Host

  1. Open EC2 Dashboard in the AWS Console: https://console.aws.amazon.com/ec2
  2. Click on Running Instances and look for the instance with a “Bastion Host” name and select it
  3. Click Connect
  4. Select “EC2 Instance Connect”

For more information on EC2 Instance Connect and other options for connecting to your bastion host, see this documentation: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-connect-methods.html

Access Sock Shop

  1. Log in to the bastion host, and run

    1. kubectl get svc -o wide -n sock-shop | grep LoadBalancer
  2. Copy the load balancer’s DNS name

    1. Sample: a34.us-east-1.elb.amazonaws.com
  3. Paste this DNS into a browser to access the sock shop front-end
  4. Navigate around to get a feel of all the functions of the shop. Things to try out:

    1. Register and Log in
    2. Viewing various items
    3. Adding and removing items to and from cart
    4. Checking out items

Deploy Gremlin

  1. In your bastion host, clone the Gremlin daemonset with git clone https://github.com/AnaMMedina21/gremlin.git
  2. Then edit the daemonset withvi gremlin/daemonset.yaml. In this file we need to edit 2 fields, Team ID and Team Secret

    1. To get your Team ID:
    2. Within Gremlin, access your company settings and click to the Teams tab, and your Team ID will be listed in the row. Copy this value.
    3. Inside the daemonset YAML file, find the line that says “value: , and replace with the Team ID value that you copied from Gremlin.
    4. To get your Team Secret:
    5. In Gremlin, under the same Teams tab, click Reset in Secret Key. Copy this value as it’s viewable only once.
    6. Inside the daemonset YAML file, find the line that says “value: , and replace it with the Team Secret you previously copied from Gremlin.
  3. Save your file and exit.

  1. We’re now ready to deploy the daemonset. Run kubectl apply -f gremlin/daemonset.yaml
  2. Check https://app.gremlin.com/clients/infrastructure to ensure clients are now available and active.

Running a Chaos Experiment

1st Experiment (Scenario)

For this first experiment, we will check to see if this cluster has autoscaling policies dialed in correctly.

  1. Click https://app.gremlin.com/scenarios/recommended and Click on “View Details” for “Validate Auto-Scaling” scenario
  2. Scroll to the bottom and click Add targets and run
  3. Select all 3 hosts found and click Run Scenario

1st Experiment (Scenario) Questions

  1. Look into Container insights
  2. Was this failure detected?
  3. Did the outcome of this failure result in expected behaviors?
  4. Would the service be able to handle this failure?

Remediation: Setup Auto-Scaling

Go to the AWS Console, Select ec2 from Services.

On the left navigation bar, select AutoScaling Groups.

Each Cluster get it’s own Auto-Scaling Group, select the one you need, and then at the lower navigation, select “Scaling Policies”

Select “Add Policy”, then “Create a simple scaling policy”

We will be creating two of these, one to scale up and one to set back to the usual 3.

Give the Policy a name, we will call it “Cluster-ScaleUp” and select “Create New Alarm”. Create the alarm to go off when CPU Util is greater than or equal to 13% for at least 1 minute, and name it Cluster-ScaleUp.

Press “Create Alarm”

Now you will be taken back to finish editing the policy

You want to edit the values to add “1” instance and then wait 120 seconds before the next activity. Press Create when finished.

We want to follow the same steps as above, but instead the policy will be called “Cluster-ScaleDown”, we will be creating a new alarm. This Alarm will be for when CPUUtilization is less than or equal to (<=) 13% within 15 minutes.

<Re-run scenario #1? Customize your scenario if you would like to see more auto scaling events kick off

2nd Experiment

For this experiment, we will test and discover what happens when there is network degradation as your primary service attempts to request a downstream dependency.

  1. In Gremlin, create a new attack: https://app.gremlin.com/attacks/new
  2. Select the Containers tab
  3. In the Search bar, look up carts-db

  1. Scroll down and click “Choose a Gremlin”
  2. Select “Network” -> “Latency” Gremlin
  3. Change the length of the attack to 300 seconds, and set MS to 1000
  4. Click Unleash Gremlin

2nd Experiment Questions

  1. As the attack is running, try the following:

    1. Add items to the cart
    2. Remove items from the cart
    3. Update quantity of items in cart
  2. Is there any customer impact?
  3. Are systems recovering gracefully?
  4. Is there any way to mitigate this?
  5. In https://app.gremlin.com/attacks/infrastructure, click Halt All Attacks to stop this attack.
  6. Did systems recover?
  7. What did we learn?

3rd Experiment

For this experiment, we will test what happens if a container were to fail. Sometimes, especially in a containerized environment, your orchestration can automatically recover, but it takes time to detect and fix the issue, resulting in a potential partial outage.

  1. In Gremlin, create a new attack: https://app.gremlin.com/attacks/new
  2. Select the Containers tab
  3. In the Search bar, look up carts-db

  1. Scroll down and click “Choose a Gremlin”
  2. Select “State” -> “Shutdown” Gremlin
  3. Switch off “Reboot”
  4. Click Unleash Gremlin

3rd Experiment Questions

  1. As the attack is running, try the following:

    1. Add items to Cart
    2. Access items in Cart
    3. Remove items in Cart
    4. Check out
  2. Is there any customer impact?
  3. Are systems recovering gracefully?

    1. How long did it take?
    2. Is full customer experience restored?
  4. How might you mitigate this?

Running a Chaos Experiment

Create Your Own Experiment!

Now that you’ve had a chance to run some pre-planned experiments, you can create your own experiment from start to finish. There is no wrong way to create an experiment, but it’s important to go through the full thought process.

Use the Blank Chaos Experiment card above to start forming a scenario. Then create this attack in Gremlin!

Key Questions to Ask

  1. Was this failure detected?
  2. Did this failure have customer impact?

    1. If so, what are they?
  3. Did the impact of this failure expected, or, did it match your hypothesis?

    1. If not, what happened instead?
  4. Can this failure be handled or mitigated?

Break Through

Join over 3000+ Engineers in the Chaos Engineering Community Slack: Join Us

Conclusion

We would love to know your thoughts on today's bootcamp, please take 1-2 minutes to let us know how we did:

FAQ

Where should I go to get support?

To get support, head to https://gremlin.com/slack to join the community, and join the #aws-gamedaylounge channel.

Can I replay this workshop on my own?

If you want to spin up this demo environment, the CloudFormation template to do so is located here.

By default, you will have to deploy this template in us-east-1.

Following completion of this deploy, you can then replay the workshop in this site.

What do I do with my Gremlin account?

Your Gremlin account is yours to keep and use! However, after 30 days, it will downgrade to Gremlin Free, with some additional limits. For more information, please visit https://www.gremlin.com/pricing/.

Avoid downtime. Use Gremlin to turn failure into resilience.

Gremlin empowers you to proactively root out failure before it causes downtime. Use Gremlin for Free and see how you can harness chaos to build resilient systems.

Use For Free