Custom Workflow with MyHub using Litmus Portal
Tags: kubernetes, litmuschaos, workflow, chaosengineering
Published: 2021-01-07 12:04:03

Hello Chaos Engineers,
In this article, we will get to know about one of the salient features of Litmus Portal i.e **My Hub**. We will go through the steps from connecting a hub to creating a custom workflow. My Hub allows SREs to orchestrate their Litmus Experiments directly from their respective Github repositories. 
##What is Litmus and how we can run chaos experiments using Litmus Portal?
[Litmus](https://github.com/litmuschaos/litmus/) is an open-source chaos engineering framework that provides tools to set up chaos in Kubernetes to help developers and SREs discover weaknesses and flaws in the application system. It is very easy to use and comes with detailed documentation. It also provides a large collection of chaos experiments, which you can find here. If you want to get started with Litmus Portal and how to create a custom workflow, this article is surely going to help you. You can also join our slack community for an open discussion.
Litmus Portal allows you to create, run and analyze the chaos workflows using a UI console. SREs can invite their team members to work on different projects and analyze the workflows present in the projects. Currently the Litmus Portal is in beta-0 version and lots of improvements are being added on a daily basis. 

##Steps involving the creation of custom workflows using MyHub are :
1. **Using the Default MyHub:**
When a user creates a project on Litmus Portal, a default MyHub is provided to the user. It is similar to the [Litmus ChaosHub](http://hub.litmuschaos.io/).
![Screenshot from 2020-12-27 22-25-22](https://dev-to-uploads.s3.amazonaws.com/i/ubc6b0iy7k8e52wt5l8n.png)
 
2. **Connecting a MyHub:**
Users can connect their chaos hubs from their Github repositories using the github link and the branch name. Once this step is done, the user can view their connected hub in the My Hub section.
![Screenshot from 2020-12-29 20-02-48](https://dev-to-uploads.s3.amazonaws.com/i/wp5j0etzic5g3pca13l4.png)
![Screenshot from 2020-12-29 20-04-38](https://dev-to-uploads.s3.amazonaws.com/i/7ljhw9ch3pfd6udbramm.png)
![Screenshot from 2020-12-29 20-04-54](https://dev-to-uploads.s3.amazonaws.com/i/s1wmmh7l0p0ecp85p1rw.png)
   
3. **View charts and experiments:**
Users can select one of the hubs and view the charts present in the particular hub. The user can view a variety of chaos experiments and these are sorted according to their types like generic, kube-aws etc. 
![Screenshot from 2020-12-27 22-25-31](https://dev-to-uploads.s3.amazonaws.com/i/w1d4x5z52akle66bg459.png) 
The user can then select one of the charts and view the details about the experiments. 
![Screenshot from 2020-12-27 22-25-36](https://dev-to-uploads.s3.amazonaws.com/i/hr0c8s5bhy3ti5i79fqp.png)
![Screenshot from 2020-12-27 22-25-48](https://dev-to-uploads.s3.amazonaws.com/i/rw7yygs97grev7ymg5j9.png)
The user can install the experiment using the experiment link, the user can also setup a service account using the RBAC link and we also provide the link for chaos engine which is highly configurable.

4. **Customize your workflows using MyHubs:**
The users can click the “Create your own workflow” card in the pre-defined templates section to start creating the custom workflows.
![Screenshot from 2020-12-29 21-54-30](https://dev-to-uploads.s3.amazonaws.com/i/5yp2ftt32jn27txy42ll.png)
 
Here the user can select a hub and choose the experiment from the different My Hubs present in the project. The user can also specify the namespace where he wants to run the chaos experiment.
After selecting the experiment from the hub, the user can now customize the experiment, the users can now tune the workflow according to their requirement.
 
* **The users can edit the appinfo which includes the appns, applabel, appkind.**
*To know more about appns, applable etc, please check the [Litmus Docs](https://docs.litmuschaos.io/docs/chaosengine/)*
![Screenshot from 2020-12-29 21-54-40](https://dev-to-uploads.s3.amazonaws.com/i/r0y1e5xfgr45bt3czeid.png)
 
* **The users can tune the variables of the chaos engine and add more key value pairs as necessary.**
![Screenshot from 2020-12-29 21-54-43](https://dev-to-uploads.s3.amazonaws.com/i/rngce5yq2iq1cwe5qtzo.png)
 
Once the user has customized the experiment , more experiments can be added to the workflows. The user can also alter the sequence of the experiments in the workflow according to the requirements. Once the user clicks the Finish adding the experiments button, a YAML is generated consisting of the experiment details that the user has selected while configuring the workflow.

Here in this custom workflow, I have selected two experiemnts `generic/pod-delete` and `generic/pod-cpu-hog`. The generated YAML comprising these two experiment is 
```
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  name: custom-chaos-workflow-1609259040
  namespace: litmus
spec:
  arguments:
    parameters:
      - name: adminModeNamespace
        value: litmus
  entrypoint: custom-chaos
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
  serviceAccountName: argo-chaos
  templates:
    - name: custom-chaos
      steps:
        - - name: install-chaos-experiments
            template: install-chaos-experiments
        - - name: pod-delete
            template: pod-delete
        - - name: pod-cpu-hog
            template: pod-cpu-hog
        - - name: revert-chaos
            template: revert-chaos
    - name: install-chaos-experiments
      container:
        args:
          - kubectl apply -f
            https://github.com/litmuschaos/chaos-charts/raw/master/charts/generic/pod-delete/experiment.yaml
            -n {{workflow.parameters.adminModeNamespace}} | kubectl apply -f
            https://github.com/litmuschaos/chaos-charts/raw/master/charts/generic/pod-cpu-hog/experiment.yaml
            -n {{workflow.parameters.adminModeNamespace}} | sleep 30
        command:
          - sh
          - -c
        image: lachlanevenson/k8s-kubectl
    - name: pod-delete
      inputs:
        artifacts:
          - name: pod-delete
            path: /tmp/chaosengine-pod-delete.yaml
            raw:
              data: |
                apiVersion: litmuschaos.io/v1alpha1
                kind: ChaosEngine
                metadata:
                  name: pod-delete
                  namespace: "{{workflow.parameters.adminModeNamespace}}"
                spec:
                  appinfo:
                    appns: default
                    applabel: app=nginx
                    appkind: deployment
                  annotationCheck: "false"
                  engineState: active
                  chaosServiceAccount: litmus-admin
                  monitoring: false
                  jobCleanUpPolicy: delete
                  experiments:
                    - name: pod-delete
                      spec:
                        components:
                          env:
                            - name: TOTAL_CHAOS_DURATION
                              value: "30"
                            - name: CHAOS_INTERVAL
                              value: "10"
                            - name: FORCE
                              value: "false"
      container:
        args:
          - -file=/tmp/chaosengine-pod-delete.yaml
          - -saveName=/tmp/engine-name
        image: litmuschaos/litmus-checker:latest
    - name: pod-cpu-hog
      inputs:
        artifacts:
          - name: pod-cpu-hog
            path: /tmp/chaosengine-pod-cpu-hog.yaml
            raw:
              data: |
                apiVersion: litmuschaos.io/v1alpha1
                kind: ChaosEngine
                metadata:
                  name: pod-cpu-hog
                  namespace: "{{workflow.parameters.adminModeNamespace}}"
                spec:
                  annotationCheck: "false"
                  engineState: active
                  appinfo:
                    appns: default
                    applabel: app=nginx
                    appkind: deployment
                  chaosServiceAccount: litmus-admin
                  monitoring: false
                  jobCleanUpPolicy: delete
                  experiments:
                    - name: pod-cpu-hog
                      spec:
                        components:
                          env:
                            - name: CPU_CORES
                              value: "1"
                            - name: TOTAL_CHAOS_DURATION
                              value: "60"
      container:
        args:
          - -file=/tmp/chaosengine-pod-cpu-hog.yaml
          - -saveName=/tmp/engine-name
        image: litmuschaos/litmus-checker:latest
    - name: revert-chaos
      container:
        args:
          - kubectl delete chaosengines --all -n
            {{workflow.parameters.adminModeNamespace}}
        command:
          - sh
          - -c
        image: lachlanevenson/k8s-kubectl 
```

Now the user can run the workflow and see the results in the analytics section. Once the workflow execution is completed , the user can view the workflow in a graphical format that consists of all useful informations like the nodes, step groups etc.
![Screenshot from 2021-01-07 11-24-59](https://dev-to-uploads.s3.amazonaws.com/i/offs8jzykv3ltx8xgx2l.png)
 

#**Conclusion**#
Now you are not limited to some predefined workflows, even if you are beginner. You are getting your own chaos template that it highly customisable. Using the Public Hub and your own My Hub, you get all the chaos experiments at one place. You can play around with all the configuration from the UI and check the changes that are happening in the workflow. 

Feel free to check out our ongoing project - [Litmus Portal](https://github.com/litmuschaos/litmus/tree/master/litmus-portal) and do let us know if you have any suggestions or feedback regarding the same. You can always submit a PR if you find any required changes. 

Make sure to reach out to us if you have any feedback or queries. Hope you found the blog informative!

If chaos engineering is something that excites you or if you want know more about cloud native chaos engineering, don’t forget to checkout our [Litmus website](https://litmuschaos.io/), [ChaosHub](https://hub.litmuschaos.io/) and the [Litmus repo](https://github.com/litmuschaos/litmus). Do leave a star if you find it insightful. 😊

I would love to invite you to our community to stay connected with us and get your Chaos Engineering doubts cleared.
To join our slack please follow the following steps!
**Step 1:** Join the Kubernetes slack using the following link: https://slack.k8s.io/
**Step 2:** Join the `#litmus` channel on the Kubernetes slack or use this link after joining the Kubernetes slack: https://slack.litmuschaos.io/

Cheers!