Gremlin is a Chaos Engineering Platform. It can be used to test your application and infrastructure resilience to unexpected failures.
In this tutorial, we will show you how to trigger a chaos engineering attack after a deployment has completed.
You will require:
- A Gremlin account
- A Humanitec account
- If you have not already done so, you need to install Gremlin to the Kubernetes cluster which is also running your Humanitec applications.
- If you have not connected your own Kubernetes cluster to Humanitec you can learn about it here.
In the Gremlin UI you can explore the different options of running chaos engineering attacks against your Kubernetes cluster and applications.
Any of those attacks can also be triggered via the Gremlin API. Construct the object that will be sent in the payload by following the docs.
Getting your Gremlin Team ID
Visit the Teams page in Gremlin, and then click on your team’s name in the list.
On the Teams screen click on Configuration.
Retrieving a Gremlin Bearer token
All requests to the Gremlin API require a token to be passed in the Authorization header. You can find details on obtaining your bearer token here: Gremlin API Docs: Authentication and access tokens.
In summary, they can be obtained via a request to the /users/auth endpoint if your provide your email and password in the body of the request:
<p> CODE:<script src="https://gist.github.com/eskilavelon/2ad4c1eeac7b0432fa3d0f97d300d7be.js"></script>
Create a Webhook in Humanitec
To trigger an attack after a deployment through Humanitec you can define a webhook to point the Gremlin API with a custom payload.
- Enter an ID you will use to identify this webhook in future. It must be a valid Humanitec ID.
- Enter the URL that defines the attack you wish to perform. Remember to include your Gremlin Team ID.
- Click the Headers button and set the Key field to Authorization and the Value field to Bearer followed by a space and then the token you retrieved in the previous step.
- Click the Payload button and enter the appropriate payload as defined in the Gremlin API Documentation.
- Select the Deployment → Finished trigger to make the webhook be fired once every deployment has completed.
Click the Create button and finish setting up the webhook.