@@ -8,35 +8,57 @@ slug: "getting-started"
88
99Cortex is a powerful platform software that can be run in two modes: as a single binary or as multiple
1010independent [ microservices] ( ../architecture.md ) .
11+
12+ There are two guides in this section:
13+
14+ 1 . [ Single Binary Mode with Docker Compose] ( #single-binary-mode )
15+ 2 . [ Microservice Mode with KIND] ( #microservice-mode )
16+
17+ The single binary mode is useful for testing and development, while the microservice mode is useful for production.
18+
19+ Both guides will help you get started with Cortex using [ blocks storage] ( ../blocks-storage/_index.md ) .
20+
21+ ## Single Binary Mode
22+
1123This guide will help you get started with Cortex in single-binary mode using
1224[ blocks storage] ( ../blocks-storage/_index.md ) .
1325
14- ## Prerequisites
26+ ### Prerequisites
1527
1628Cortex can be configured to use local storage or cloud storage (S3, GCS, and Azure). It can also utilize external
1729Memcached and Redis instances for caching. This guide will focus on running Cortex as a single process with no
1830dependencies.
1931
2032* [ Docker Compose] ( https://docs.docker.com/compose/install/ )
2133
22- ## Running Cortex as a Single Instance
34+ ### Running Cortex as a Single Instance
2335
2436For simplicity, we'll start by running Cortex as a single process with no dependencies. This mode is not recommended or
2537intended for production environments or production use.
2638
2739This example uses [ Docker Compose] ( https://docs.docker.com/compose/ ) to set up:
2840
29411 . An instance of [ SeaweedFS] ( https://github.com/seaweedfs/seaweedfs/ ) for S3-compatible object storage
30- 1 . An instance of [ Cortex] ( https://cortexmetrics.io/ ) to receive metrics
31- 1 . An instance of [ Prometheus] ( https://prometheus.io/ ) to send metrics to Cortex
32- 1 . An instance of [ Grafana] ( https://grafana.com/ ) to visualize the metrics
33-
34- ### Instructions
42+ 1 . An instance of [ Cortex] ( https://cortexmetrics.io/ ) to receive metrics.
43+ 1 . An instance of [ Prometheus] ( https://prometheus.io/ ) to send metrics to Cortex.
44+ 1 . An instance of [ Grafana] ( https://grafana.com/ ) to visualize the metrics.
3545
36- #### Start the services
46+ #### Instructions
3747
3848``` sh
3949$ cd docs/getting-started
50+ ```
51+
52+ ##### Start the services
53+
54+ ``` sh
55+ # Start SeaweedFS to emulate S3 storage for Cortex.
56+ $ docker-compose up seaweedfs -d --wait
57+ # Create buckets in SeaweedFS.
58+ $ for bucket in cortex-blocks cortex-ruler cortex-alertmanager; do
59+ curl --aws-sigv4 " aws:amz:local:seaweedfs" --user " any:any" -X PUT http://localhost:8333/$bucket
60+ done
61+ # Start the remaining services.
4062$ docker-compose up -d --wait
4163```
4264
@@ -51,31 +73,22 @@ If everything is working correctly, Prometheus should be sending metrics that it
5173configured to send metrics to Cortex via ` remote_write ` . Check out the ` prometheus-config.yaml ` file to see
5274how this is configured.
5375
54- #### Configure SeaweedFS (S3)
55-
56- ``` sh
57- # Create buckets in SeaweedFS
58- $ curl --aws-sigv4 " aws:amz:local:seaweedfs" --user " any:any" -X PUT http://localhost:8333/cortex-blocks
59- $ curl --aws-sigv4 " aws:amz:local:seaweedfs" --user " any:any" -X PUT http://localhost:8333/cortex-ruler
60- $ curl --aws-sigv4 " aws:amz:local:seaweedfs" --user " any:any" -X PUT http://localhost:8333/cortex-alertmanager
61- ```
62-
6376#### Configure Cortex Recording Rules and Alerting Rules
6477
6578We can configure Cortex with [ cortextool] ( https://github.com/cortexproject/cortex-tools/ ) to load [ recording rules] ( https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/ ) and [ alerting rules] ( https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/ ) . This is optional, but it is helpful to see how Cortex can be configured to manage rules and alerts.
6679
6780``` sh
68- # Configure recording rules for the cortex tenant (optional)
69- $ docker run --network host -v $( pwd) :/workspace -w /workspace quay.io/cortexproject/cortex-tools:v0.17.0 rules sync rules.yaml alerts.yaml --id cortex --address http://localhost:9009
81+ # Configure recording rules for the Cortex tenant (optional)
82+ $ docker run --network host -v " $( pwd) :/workspace" -w /workspace quay.io/cortexproject/cortex-tools:v0.17.0 rules sync rules.yaml alerts.yaml --id cortex --address http://localhost:9009
7083```
7184
7285#### Configure Cortex Alertmanager
7386
7487Cortex also comes with a multi-tenant Alertmanager. Let's load configuration for it to be able to view them in Grafana.
7588
7689``` sh
77- # Configure alertmanager for the cortex tenant
78- $ docker run --network host -v $( pwd) :/workspace -w /workspace quay.io/cortexproject/cortex-tools:v0.17.0 alertmanager load alertmanager-config.yaml --id cortex --address http://localhost:9009
90+ # Configure alertmanager for the Cortex tenant
91+ $ docker run --network host -v " $( pwd) :/workspace" -w /workspace quay.io/cortexproject/cortex-tools:v0.17.0 alertmanager load alertmanager-config.yaml --id cortex --address http://localhost:9009
7992```
8093
8194You can configure Alertmanager in [ Grafana as well] ( http://localhost:3000/alerting/notifications?search=&alertmanager=Cortex%20Alertmanager ) .
@@ -97,22 +110,22 @@ via `remote_write`!
97110Other things to explore:
98111
99112- [ Cortex] ( http://localhost:9009 ) - Administrative interface for Cortex
100- - Try shutting down the ingester, and see how it affects metric ingestion.
101- - Restart Cortex to bring the ingester back online, and see how Prometheus catches up.
102- - Does it affect the querying of metrics in Grafana?
113+ - Try shutting down the ingester, and see how it affects metric ingestion.
114+ - Restart Cortex to bring the ingester back online, and see how Prometheus catches up.
115+ - Does it affect the querying of metrics in Grafana?
103116- [ Prometheus] ( http://localhost:9090 ) - Prometheus instance that is sending metrics to Cortex
104- - Try querying the metrics in Prometheus.
105- - Are they the same as what you see in Cortex?
117+ - Try querying the metrics in Prometheus.
118+ - Are they the same as what you see in Cortex?
106119- [ Grafana] ( http://localhost:3000 ) - Grafana instance that is visualizing the metrics.
107- - Try creating a new dashboard and adding a new panel with a query to Cortex.
120+ - Try creating a new dashboard and adding a new panel with a query to Cortex.
108121
109122### Clean up
110123
111124``` sh
112125$ docker-compose down
113126```
114127
115- ## Running Cortex in microservice mode
128+ ## Microservice Mode
116129
117130Now that you have Cortex running as a single instance, let's explore how to run Cortex in microservice mode.
118131
@@ -159,39 +172,40 @@ $ kubectl create namespace cortex
159172
160173``` sh
161174# We can emulate S3 with SeaweedFS
162- $ kubectl -n cortex apply -f seaweedfs.yaml
175+ $ kubectl --namespace cortex apply -f seaweedfs.yaml --wait --timeout=5m
163176```
164177
165178``` sh
166179# Wait for SeaweedFS to be ready
167- $ kubectl -n cortex wait --for=condition=ready pod -l app=seaweedfs
180+ $ sleep 5
181+ $ kubectl --namespace cortex wait --for=condition=ready pod -l app=seaweedfs --timeout=5m
168182```
169183
170184``` sh
171185# Port-forward to SeaweedFS to create a bucket
172- $ kubectl -n cortex port-forward svc/seaweedfs 8333
186+ $ kubectl --namespace cortex port-forward svc/seaweedfs 8333 &
173187```
174188
175189``` sh
176190# Create buckets in SeaweedFS
177- $ curl --aws-sigv4 " aws:amz:local:seaweedfs " --user " any:any " -X PUT http://localhost:8333/ cortex-blocks
178- $ curl --aws-sigv4 " aws:amz:local:seaweedfs" --user " any:any" -X PUT http://localhost:8333/cortex-ruler
179- $ curl --aws-sigv4 " aws:amz:local:seaweedfs " --user " any:any " -X PUT http://localhost:8333/cortex-alertmanager
191+ $ for bucket in cortex-blocks cortex-ruler cortex-alertmanager ; do
192+ curl --aws-sigv4 " aws:amz:local:seaweedfs" --user " any:any" -X PUT http://localhost:8333/$bucket
193+ done
180194```
181195
182196#### Setup Cortex
183197
184198``` sh
185199# Deploy Cortex using the provided values file which configures
186200# - blocks storage to use the seaweedfs service
187- $ helm upgrade --install --version=2.4.0 --namespace cortex cortex cortex-helm/cortex -f cortex-values.yaml
201+ $ helm upgrade --install --version=2.4.0 --namespace cortex cortex cortex-helm/cortex -f cortex-values.yaml --wait
188202```
189203
190204#### Setup Prometheus
191205
192206``` sh
193207# Deploy Prometheus to scrape metrics in the cluster and send them, via remote_write, to Cortex.
194- $ helm upgrade --install --version=25.20.1 --namespace cortex prometheus prometheus-community/prometheus -f prometheus-values.yaml
208+ $ helm upgrade --install --version=25.20.1 --namespace cortex prometheus prometheus-community/prometheus -f prometheus-values.yaml --wait
195209```
196210
197211If everything is working correctly, Prometheus should be sending metrics that it is scraping to Cortex. Prometheus is
@@ -202,32 +216,34 @@ how this is configured.
202216
203217``` sh
204218# Deploy Grafana to visualize the metrics that were sent to Cortex.
205- $ helm upgrade --install --version=7.3.9 --namespace cortex grafana grafana/grafana -f grafana-values.yaml
219+ $ helm upgrade --install --version=7.3.9 --namespace cortex grafana grafana/grafana -f grafana-values.yaml --wait
206220```
207221
208222``` sh
209223# Create dashboards for Cortex
210224$ for dashboard in $( ls dashboards) ; do
211225 basename=$( basename -s .json $dashboard )
212226 cmname=grafana-dashboard-$basename
213- kubectl create -n cortex cm $cmname --from-file=$dashboard =dashboards/$dashboard --save-config=true -o yaml --dry-run=client | kubectl apply -f -
214- kubectl patch -n cortex cm $cmname -p ' {"metadata":{"labels":{"grafana_dashboard":""}}}'
227+ kubectl create --namespace cortex configmap $cmname --from-file=$dashboard =dashboards/$dashboard --save-config=true -o yaml --dry-run=client | kubectl apply -f -
228+ kubectl patch --namespace cortex configmap $cmname -p ' {"metadata":{"labels":{"grafana_dashboard":""}}}'
215229done
216230
217231```
218232
219233``` sh
220234# Port-forward to Grafana to visualize
221- kubectl --namespace cortex port-forward deploy/grafana 3000
235+ $ kubectl --namespace cortex port-forward deploy/grafana 3000 &
222236```
223237
238+ View the dashboards in [ Grafana] ( http://localhost:3000/dashboards?tag=cortex ) .
239+
224240#### Configure Cortex Recording Rules and Alerting Rules (Optional)
225241
226242We can configure Cortex with [ cortextool] ( https://github.com/cortexproject/cortex-tools/ ) to load [ recording rules] ( https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/ ) and [ alerting rules] ( https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/ ) . This is optional, but it is helpful to see how Cortex can be configured to manage rules and alerts.
227243
228244``` sh
229245# Port forward to the alertmanager to configure recording rules and alerts
230- $ kubectl --namespace cortex port-forward svc/cortex-nginx 8080:80
246+ $ kubectl --namespace cortex port-forward svc/cortex-nginx 8080:80 &
231247```
232248
233249``` sh
@@ -266,7 +282,7 @@ Other things to explore:
266282
267283``` sh
268284# Port forward to the ingester to see the administrative interface for Cortex
269- $ kubectl --namespace cortex port-forward deploy/cortex-ingester 9009:8080
285+ $ kubectl --namespace cortex port-forward deploy/cortex-ingester 9009:8080 &
270286```
271287
272288- Try shutting down the ingester, and see how it affects metric ingestion.
@@ -277,7 +293,7 @@ $ kubectl --namespace cortex port-forward deploy/cortex-ingester 9009:8080
277293
278294``` sh
279295# Port forward to Prometheus to see the metrics that are being scraped
280- $ kubectl --namespace cortex port-forward deploy/prometheus-server 9090
296+ $ kubectl --namespace cortex port-forward deploy/prometheus-server 9090 &
281297```
282298- Try querying the metrics in Prometheus.
283299- Are they the same as what you see in Cortex?
@@ -286,13 +302,19 @@ $ kubectl --namespace cortex port-forward deploy/prometheus-server 9090
286302
287303``` sh
288304# Port forward to Grafana to visualize
289- $ kubectl --namespace cortex port-forward deploy/grafana 3000
305+ $ kubectl --namespace cortex port-forward deploy/grafana 3000 &
290306```
291307
292308- Try creating a new dashboard and adding a new panel with a query to Cortex.
293309
294310### Clean up
295311
312+ ``` sh
313+ # Remove the port-forwards
314+ $ killall kubectl
315+ ```
316+
296317``` sh
297318$ kind delete cluster
298319```
320+
0 commit comments