|
| 1 | +--- |
| 2 | +id: chaoscenter-developer-guide |
| 3 | +title: ChaosCenter Developer Guide |
| 4 | +sidebar_label: ChaosCenter Developer Guide |
| 5 | +--- |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## **Prerequisites** |
| 10 | +:::note |
| 11 | +This document is intended to be implemented locally. Please do not use in dev or prod environments. |
| 12 | +::: |
| 13 | + |
| 14 | +- Kubernetes 1.17 or later |
| 15 | +- Helm3 or Kubectl |
| 16 | +- Node and npm |
| 17 | +- Docker |
| 18 | +- Golang |
| 19 | +- Local Kubernetes Cluster (via minikube, k3s or kind) |
| 20 | + |
| 21 | +## **Control Plane** |
| 22 | +Backend components consist of three microservices |
| 23 | +1. GraphQL server |
| 24 | +2. Authentication server |
| 25 | +3. MongoDB |
| 26 | + |
| 27 | +Frontend component |
| 28 | +1. React |
| 29 | + |
| 30 | +## **Steps to run the Control Plane** |
| 31 | + |
| 32 | +### 1. Run MongoDB |
| 33 | + |
| 34 | +Step-1: Pull and run the image |
| 35 | + |
| 36 | +```bash |
| 37 | +docker pull mongo:5 |
| 38 | + |
| 39 | +docker network create mongo-cluster |
| 40 | + |
| 41 | +docker run -d --net mongo-cluster -p 27015:27015 --name m1 mongo:4.2 mongod --replSet rs0 --port 27015 |
| 42 | +docker run -d --net mongo-cluster -p 27016:27016 --name m2 mongo:4.2 mongod --replSet rs0 --port 27016 |
| 43 | +docker run -d --net mongo-cluster -p 27017:27017 --name m3 mongo:4.2 mongod --replSet rs0 --port 27017 |
| 44 | +``` |
| 45 | + |
| 46 | +Step-2: Add hosts |
| 47 | + |
| 48 | +import Tabs from '@theme/Tabs'; |
| 49 | +import TabItem from '@theme/TabItem'; |
| 50 | + |
| 51 | +<Tabs groupId="operating-systems"> |
| 52 | +<TabItem value="win" label="Windows"> |
| 53 | + |
| 54 | +```bash |
| 55 | +# add hosts in hosts |
| 56 | +notepad C:\Windows\System32\drivers\etc\hosts |
| 57 | + |
| 58 | +# add the below line |
| 59 | +127.0.0.1 m1 m2 m3 |
| 60 | +``` |
| 61 | + |
| 62 | +</TabItem> |
| 63 | +<TabItem value="linux" label="macOS/Linux"> |
| 64 | + |
| 65 | +```bash |
| 66 | +# add hosts in hosts |
| 67 | +sudo vim /etc/hosts |
| 68 | + |
| 69 | +# add the below line |
| 70 | +127.0.0.1 m1 m2 m3 |
| 71 | +``` |
| 72 | + |
| 73 | +</TabItem> |
| 74 | +</Tabs> |
| 75 | + |
| 76 | + |
| 77 | +Step-3: Configure the mongoDB replica set |
| 78 | + |
| 79 | +```bash |
| 80 | +docker exec -it m1 mongo -port 27015 |
| 81 | + |
| 82 | +config={"_id":"rs0","members":[{"_id":0,"host":"m1:27015"},{"_id":1,"host":"m2:27016"},{"_id":2,"host":"m3:27017"}]} |
| 83 | + |
| 84 | +rs.initiate(config) |
| 85 | + |
| 86 | +db.getSiblingDB("admin").createUser({user:"admin",pwd:"1234",roles:[{role:"root",db:"admin"}]}); |
| 87 | +``` |
| 88 | + |
| 89 | +### 2. Run the Authentication Server |
| 90 | + |
| 91 | +:::note |
| 92 | +Make sure to run backend services before the frontend. If you haven’t already cloned the litmus project do so from the `litmuschaos/litmus` repository |
| 93 | +::: |
| 94 | + |
| 95 | +```bash |
| 96 | +git clone https://github.com/litmuschaos/litmus.git litmus --depth 1 |
| 97 | +``` |
| 98 | + |
| 99 | + |
| 100 | +Step-1: Export the following environment variables |
| 101 | + |
| 102 | +```bash |
| 103 | +export ADMIN_USERNAME=admin |
| 104 | +export ADMIN_PASSWORD=litmus |
| 105 | +export DB_SERVER="mongodb://m1:27015,m2:27016,m3:27017/?replicaSet=rs0" |
| 106 | +export DB_USER=admin |
| 107 | +export DB_PASSWORD=1234 |
| 108 | +export JWT_SECRET=litmus-portal@123 |
| 109 | +export PORTAL_ENDPOINT=http://localhost:8080 |
| 110 | +export LITMUS_SVC_ENDPOINT="" |
| 111 | +export SELF_AGENT=false |
| 112 | +export INFRA_SCOPE=cluster |
| 113 | +export INFRA_NAMESPACE=litmus |
| 114 | +export LITMUS_PORTAL_NAMESPACE=litmus |
| 115 | +export PORTAL_SCOPE=namespace |
| 116 | +export SUBSCRIBER_IMAGE=litmuschaos/litmusportal-subscriber:ci |
| 117 | +export EVENT_TRACKER_IMAGE=litmuschaos/litmusportal-event-tracker:ci |
| 118 | +export CONTAINER_RUNTIME_EXECUTOR=k8sapi |
| 119 | +export ARGO_WORKFLOW_CONTROLLER_IMAGE=argoproj/workflow-controller:v2.11.0 |
| 120 | +export ARGO_WORKFLOW_EXECUTOR_IMAGE=argoproj/argoexec:v2.11.0 |
| 121 | +export CHAOS_CENTER_SCOPE=cluster |
| 122 | +export WORKFLOW_HELPER_IMAGE_VERSION=3.0.0 |
| 123 | +export LITMUS_CHAOS_OPERATOR_IMAGE=litmuschaos/chaos-operator:3.0.0 |
| 124 | +export LITMUS_CHAOS_RUNNER_IMAGE=litmuschaos/chaos-runner:3.0.0 |
| 125 | +export LITMUS_CHAOS_EXPORTER_IMAGE=litmuschaos/chaos-exporter:3.0.0 |
| 126 | +export VERSION=ci |
| 127 | +export HUB_BRANCH_NAME=v2.0.x |
| 128 | +export INFRA_DEPLOYMENTS="[\"app=chaos-exporter\", \"name=chaos-operator\", \"app=event-tracker\",\"app=workflow-controller\"]" |
| 129 | +export INFRA_COMPATIBLE_VERSIONS='["0.2.0", "0.1.0","ci"]' |
| 130 | +export DEFAULT_HUB_BRANCH_NAME=master |
| 131 | +export ENABLE_INTERNAL_TLS=false |
| 132 | +export REST_PORT=3000 |
| 133 | +export GRPC_PORT=3030 |
| 134 | +``` |
| 135 | + |
| 136 | +<Tabs groupId="operating-systems"> |
| 137 | +<TabItem value="win" label="Windows"> |
| 138 | + |
| 139 | +Docker or Hyper-V is reserving that port range. You can use 3030 ports by running the command below |
| 140 | + |
| 141 | +```bash |
| 142 | +netsh interface ipv4 show excludedportrange protocol=tcp |
| 143 | +net stop winnat |
| 144 | +netsh int ipv4 add excludedportrange protocol=tcp startport=3030 numberofports=1 |
| 145 | +net start winnat |
| 146 | +``` |
| 147 | + |
| 148 | +</TabItem> |
| 149 | +</Tabs> |
| 150 | + |
| 151 | +Step-2: Run the go application |
| 152 | + |
| 153 | +```bash |
| 154 | +cd chaoscenter/authentication/api |
| 155 | +go run main.go |
| 156 | +``` |
| 157 | + |
| 158 | +### 3. Run the GraphQL Server |
| 159 | + |
| 160 | +Step-1: Export the following environment variables |
| 161 | + |
| 162 | +```bash |
| 163 | +export DB_SERVER="mongodb://m1:27015,m2:27016,m3:27017/?replicaSet=rs0" |
| 164 | +export DB_USER=admin |
| 165 | +export DB_PASSWORD=1234 |
| 166 | +export JWT_SECRET=litmus-portal@123 |
| 167 | +export PORTAL_ENDPOINT=http://localhost:8080 |
| 168 | +export LITMUS_SVC_ENDPOINT="" |
| 169 | +export SELF_AGENT=false |
| 170 | +export INFRA_SCOPE=cluster |
| 171 | +export INFRA_NAMESPACE=litmus |
| 172 | +export LITMUS_PORTAL_NAMESPACE=litmus |
| 173 | +export PORTAL_SCOPE=namespace |
| 174 | +export SUBSCRIBER_IMAGE=litmuschaos/litmusportal-subscriber:ci |
| 175 | +export EVENT_TRACKER_IMAGE=litmuschaos/litmusportal-event-tracker:ci |
| 176 | +export CONTAINER_RUNTIME_EXECUTOR=k8sapi |
| 177 | +export ARGO_WORKFLOW_CONTROLLER_IMAGE=argoproj/workflow-controller:v2.11.0 |
| 178 | +export ARGO_WORKFLOW_EXECUTOR_IMAGE=argoproj/argoexec:v2.11.0 |
| 179 | +export CHAOS_CENTER_SCOPE=cluster |
| 180 | +export WORKFLOW_HELPER_IMAGE_VERSION=3.0.0 |
| 181 | +export LITMUS_CHAOS_OPERATOR_IMAGE=litmuschaos/chaos-operator:3.0.0 |
| 182 | +export LITMUS_CHAOS_RUNNER_IMAGE=litmuschaos/chaos-runner:3.0.0 |
| 183 | +export LITMUS_CHAOS_EXPORTER_IMAGE=litmuschaos/chaos-exporter:3.0.0 |
| 184 | +export ADMIN_USERNAME=admin |
| 185 | +export ADMIN_PASSWORD=litmus |
| 186 | +export VERSION=ci |
| 187 | +export HUB_BRANCH_NAME=v2.0.x |
| 188 | +export INFRA_DEPLOYMENTS="[\"app=chaos-exporter\", \"name=chaos-operator\", \"app=event-tracker\",\"app=workflow-controller\"]" |
| 189 | +export INFRA_COMPATIBLE_VERSIONS='["0.2.0", "0.1.0","ci"]' |
| 190 | +export DEFAULT_HUB_BRANCH_NAME=master |
| 191 | +``` |
| 192 | + |
| 193 | +Step-2: Run the go application |
| 194 | + |
| 195 | +```bash |
| 196 | +cd chaoscenter/graphql/server |
| 197 | +go run server.go |
| 198 | +``` |
| 199 | + |
| 200 | +### 4. Run Frontend |
| 201 | + |
| 202 | +:::note |
| 203 | +Make sure to run backend services before the frontend. |
| 204 | +::: |
| 205 | + |
| 206 | +Step-1: Install all the dependencies |
| 207 | + |
| 208 | +```bash |
| 209 | +cd litmus/chaoscenter/web |
| 210 | +yarn |
| 211 | +``` |
| 212 | + |
| 213 | +Step-2: Generate the ssl certificate |
| 214 | +<Tabs groupId="operating-systems"> |
| 215 | +<TabItem value="win" label="Windows"> |
| 216 | + |
| 217 | +The command you run is in the script/generate-certificate.sh file, but it doesn't work in a Windows environment, so please run the script below instead |
| 218 | + |
| 219 | +```bash |
| 220 | +mkdir -p certificates |
| 221 | + |
| 222 | +openssl req -x509 -newkey rsa:4096 -keyout certificates/localhost-key.pem -out certificates/localhost.pem -days 365 -nodes -subj '//C=US' |
| 223 | +``` |
| 224 | + |
| 225 | +</TabItem> |
| 226 | +<TabItem value="linux" label="macOS/Linux"> |
| 227 | + |
| 228 | +```bash |
| 229 | +yarn generate-certificate |
| 230 | +``` |
| 231 | + |
| 232 | +</TabItem> |
| 233 | +</Tabs> |
| 234 | + |
| 235 | +Step-3: Run the frontend project |
| 236 | + |
| 237 | +```bash |
| 238 | +yarn dev |
| 239 | +``` |
| 240 | + |
| 241 | +> It’ll prompt you to start the development server at port `8185` or any other port than 3000 since it is already being used by the auth server. |
| 242 | +
|
| 243 | +Once you are able to see the Login Screen of Litmus use the following default credentials |
| 244 | + |
| 245 | +``` |
| 246 | +Username: admin |
| 247 | +Password: litmus |
| 248 | +``` |
| 249 | + |
| 250 | +<img src={require('../assets/login.png').default} width="800" /> |
| 251 | + |
| 252 | + |
| 253 | +## **Steps to connect Chaos Infrastructure** |
| 254 | +### Using Litmusctl |
| 255 | +Use [litmusctl](https://github.com/litmuschaos/litmusctl) on the same box/local cluster and connect an ns infrastructure |
| 256 | + |
| 257 | +### Using Chaoscenter |
| 258 | +Use Chaoscenter to connect an Infrastructure, download the manifest and apply it on k3d/minikube. Once the pods are up(except the subscriber), run the following command: |
| 259 | + |
| 260 | +```bash |
| 261 | +cd subscriber |
| 262 | + |
| 263 | +INFRA_ID=<INFRA_ID> ACCESS_KEY=<ACCESS_KEY> INFRA_SCOPE=cluster SERVER_ADDR=http://localhost:8080/query INFRA_NAMESPACE=litmus IS_INFRA_CONFIRMED="false" COMPONENTS="DEPLOYMENTS: ["app=chaos-exporter", "name=chaos-operator", "app=workflow-controller"]" START_TIME=1631089756 VERSION="ci" AGENT_POD="subscriber-78f6bd4db5-ck5d9" SKIP_ |
| 264 | +SSL_VERIFY="false" go run subscriber.go -kubeconfig ~/.kube/config |
| 265 | +``` |
0 commit comments