You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/kubernetes/README.md
+33-17
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,19 @@
1
1
# Chronos Kubernetes Example
2
2
3
3
This example demonstrates how **Chronos** can be used to track health metrics of a Kubernetes cluster when deployed with a Prometheus monitoring server. The folders in this example include the following:
4
-
-*client*: A React application (in the *client* folder) that requests a random number from a Node/Express API
5
-
-*server*: The Node/Express API that responds with the random number. This is where the **Chronos** package is actually imported and executed.
6
-
-*launch*: YAML files describing the *deployment* and *service* configurations for the client, server, and Prometheus server
7
-
-*scripts*: Scripts to automate some of the steps involved in running the example
4
+
5
+
-_client_: A React application (in the _client_ folder) that requests a random number from a Node/Express API
6
+
-_server_: The Node/Express API that responds with the random number. This is where the **Chronos** package is actually imported and executed.
7
+
-_launch_: YAML files describing the _deployment_ and _service_ configurations for the client, server, and Prometheus server
8
+
-_scripts_: Scripts to automate some of the steps involved in running the example
8
9
9
10
## Additional Documentation
10
11
11
12
For additional information on how Chronos works this example, please review the Kubernetes section in the [Chronos NPM Package README](../../chronos_npm_package/README.md).
12
13
13
14
## Install Docker Desktop
14
-
This example has been developed and tested using the Kubernetes Engine packaged in the Docker Desktop application.
15
+
16
+
This example has been developed and tested using the Kubernetes Engine packaged in the Docker Desktop application.
15
17
16
18
1. Follow instructions online to download/install Docker Desktop and to **enable the Kubernetes Engine**.
17
19
@@ -20,67 +22,76 @@ This example has been developed and tested using the Kubernetes Engine packaged
20
22
</p>
21
23
22
24
## Setup Prometheus and Grafana
23
-
1.`cd` into the *scripts* folder and run the setup script with `./setup.sh` - the process of configuring Prometheus and Grafana.
25
+
26
+
1.`cd` into the _scripts_ folder and run the setup script with `./setup.sh` - the process of configuring Prometheus and Grafana.
24
27
25
28
**Note**: If you run into `Permission denied` error, try run this command: `chmod +x [the_file_name]` in the terminal and re-run `./setup.sh`.
26
29
27
30
2. In your browser, go to `localhost:32000`, which will be the login page of grafana. Use `admin` as both username and password to login. You can change the password after login.
28
31
29
32
3. Navigate to `Home -> Administration -> Service accounts`, then click `Add service account` to create an service account. Be sure to choose `Admin` as the role. Then click `Add service account token`, hit `generate`, you are done! Remember this token, you will be using this token to access Grafana HTTP API programmatically.
30
33
31
-
4. Add a `.env` file to the *server* folder that contains the following key/value pairs:
34
+
4. Add a `.env` file to the _server_ folder that contains the following key/value pairs:
32
35
33
36
```
34
37
CHRONOS_GRAFANA_API_KEY = Bearer [the access token you created in step 3]
35
38
```
36
39
37
40
## Build the Client
38
-
1.`cd` into the *client* folder and run the following command:
41
+
42
+
1.`cd` into the _client_ folder and run the following command:
43
+
39
44
```
40
45
docker build -t frontend:1.0 .
41
46
```
42
-
**Mac Users:** Alternative to running the above command, `cd` into the scripts folder and run the `buildClient.sh` script by running `./buildClient.sh` in the terminal.
43
47
48
+
**Mac Users:** Alternative to running the above command, `cd` into the scripts folder and run the `buildClient.sh` script by running `./buildClient.sh` in the terminal.
44
49
45
50
## Build the Server
51
+
46
52
1. In the `.env` file you just created, add the following key/value pairs as well:
47
53
48
54
```
49
55
CHRONOS_DB = MongoDB or PostgreSQL
50
56
CHRONOS_URI = The URI to the desired MongoDB or PostgreSQL database to save health metrics via Chronos
51
57
```
58
+
52
59
2. Then look at the `package.json` file in the server folder and **note how `@chronosmicro/tracker` is included as a dependency:**
53
60
54
-
- If the @chronosmicro/tracker dependency is listed as a **remote npm package** (i.e. `"@chronosmicro/tracker": "^8.0.3"`), no further work is needed.
61
+
- If the @chronosmicro/tracker dependency is listed as a **remote npm package** (i.e. `"@chronosmicro/tracker": "^12.0.1"`), no further work is needed.
55
62
56
63
- If the @chronosmicro/tracker dependency is listed as a **local npm package** (i.e. `"@chronosmicro/tracker": "file:./chronos_npm_package"`), the Docker build will require that the Chronos code is in this folder. Either:
57
-
- Copy the _chronos_npm_package_ folder in manually, and **go to step 3**
58
-
-**OR**
59
-
- If you are a Mac user, you can use the `buildServer.sh` script to automate this process and **skip step 3**
60
-
- Do this by `cd`ing into the *scripts* folder and run the buildServer script with `./buildServer.sh` - the process of copying in the *chronos_npm_package* folder, performing the Docker build, and then removing the copied in folder is automated.
64
+
- Copy the _chronos_npm_package_ folder in manually, and **go to step 3**
65
+
-**OR**
66
+
- If you are a Mac user, you can use the `buildServer.sh` script to automate this process and **skip step 3**
67
+
- Do this by `cd`ing into the _scripts_ folder and run the buildServer script with `./buildServer.sh` - the process of copying in the _chronos_npm_package_ folder, performing the Docker build, and then removing the copied in folder is automated.
61
68
62
69
3. (skip if you used the `buildServer.sh` script)
63
70
64
-
`cd` into the *server* folder and run the following command:
71
+
`cd` into the _server_ folder and run the following command:
72
+
65
73
```
66
74
docker build -t backend:1.0 .
67
75
```
68
76
69
77
## Start the npm Server
78
+
70
79
1.`cd` into the `server` folder inside `chronos_npm_package`, then run `npm install` to install all dependencies.
71
80
72
81
2. run `npm start` to start npm server.
73
82
74
83
3. You should see `🤖 Example app listening on port 1111! chronos_npm_package Server Loaded 🎉` in the terminal.
75
84
76
85
## Deploy the Cluster
86
+
77
87
1.`cd` into the launch folder and run the following commands to start the services and deployments described in the YAML files:
88
+
78
89
```
79
90
kubectl apply -f backend.yml
80
91
kubectl apply -f frontend.yml
81
92
```
82
93
83
-
**Mac Users:** Alternative to running the above commands, `cd` into the *scripts* folder and run the `startKuber.sh` script.
94
+
**Mac Users:** Alternative to running the above commands, `cd` into the _scripts_ folder and run the `startKuber.sh` script.
84
95
85
96
2. Check in Docker desktop if your containers have been created. You should see something similar to the following:
86
97
@@ -98,6 +109,7 @@ Your microservice health metrics can now be viewed at the given `CHRONOS_URI` or
98
109
## Teardown the Cluster
99
110
100
111
1.`cd` into the launch folder and run the following commands to stop the running services and deployments:
**Mac Users:** Alternative to running the above commands, `cd` into the *scripts* folder and run the `stopKuber.sh` script
121
+
**Mac Users:** Alternative to running the above commands, `cd` into the _scripts_ folder and run the `stopKuber.sh` script
110
122
111
123
**Note**: The above part only teardown Prometheus and Kubernetes, it leaves Grafana running. This is because if you teardown Grafana, the next time you redeploy you will be login with a new account, the access token and dashboard you created within this account will be lost.
0 commit comments