Skip to content

Commit 342fded

Browse files
authored
Merge pull request #6115 from CharlieTLe/improve-getting-started-documentation-3
Update Kubernetes Getting Started
2 parents 4539330 + e6f95d9 commit 342fded

File tree

5 files changed

+110
-39
lines changed

5 files changed

+110
-39
lines changed

docs/getting-started/_index.md

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,29 @@ $ kubectl create namespace cortex
162162
$ kubectl -n cortex apply -f seaweedfs.yaml
163163
```
164164

165+
```sh
166+
# Wait for SeaweedFS to be ready
167+
$ kubectl -n cortex wait --for=condition=ready pod -l app=seaweedfs
168+
```
169+
165170
```sh
166171
# Port-forward to SeaweedFS to create a bucket
167172
$ kubectl -n cortex port-forward svc/seaweedfs 8333
168173
```
169174

170-
```shell
171-
# Create a bucket
172-
$ curl --aws-sigv4 "aws:amz:local:seaweedfs" --user "any:any" -X PUT http://localhost:8333/cortex-bucket
175+
```sh
176+
# 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
173180
```
174181

175182
#### Setup Cortex
176183

177184
```sh
178185
# Deploy Cortex using the provided values file which configures
179186
# - blocks storage to use the seaweedfs service
180-
$ helm upgrade --install --version=2.3.0 --namespace cortex cortex cortex-helm/cortex -f cortex-values.yaml
187+
$ helm upgrade --install --version=2.4.0 --namespace cortex cortex cortex-helm/cortex -f cortex-values.yaml
181188
```
182189

183190
#### Setup Prometheus
@@ -187,55 +194,102 @@ $ helm upgrade --install --version=2.3.0 --namespace cortex cortex cortex-helm/
187194
$ helm upgrade --install --version=25.20.1 --namespace cortex prometheus prometheus-community/prometheus -f prometheus-values.yaml
188195
```
189196

197+
If everything is working correctly, Prometheus should be sending metrics that it is scraping to Cortex. Prometheus is
198+
configured to send metrics to Cortex via `remote_write`. Check out the `prometheus-config.yaml` file to see
199+
how this is configured.
200+
190201
#### Setup Grafana
191202

192203
```sh
193204
# Deploy Grafana to visualize the metrics that were sent to Cortex.
194205
$ helm upgrade --install --version=7.3.9 --namespace cortex grafana grafana/grafana -f grafana-values.yaml
195206
```
196207

197-
#### Explore
208+
```sh
209+
# Create dashboards for Cortex
210+
$ for dashboard in $(ls dashboards); do
211+
basename=$(basename -s .json $dashboard)
212+
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":""}}}'
215+
done
216+
217+
```
198218

199219
```sh
200220
# Port-forward to Grafana to visualize
201221
kubectl --namespace cortex port-forward deploy/grafana 3000
202222
```
203223

204-
Grafana is configured to use Cortex as a data source. You can explore the data source in Grafana and query metrics. For example, this [explore](http://localhost:3000/explore?schemaVersion=1&panes=%7B%22au0%22:%7B%22datasource%22:%22P6693426190CB2316%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22expr%22:%22rate%28prometheus_remote_storage_samples_total%5B$__rate_interval%5D%29%22,%22range%22:true,%22instant%22:true,%22datasource%22:%7B%22type%22:%22prometheus%22,%22uid%22:%22P6693426190CB2316%22%7D,%22editorMode%22:%22builder%22,%22legendFormat%22:%22__auto%22,%22useBackend%22:false,%22disableTextWrap%22:false,%22fullMetaSearch%22:false,%22includeNullMetadata%22:false%7D%5D,%22range%22:%7B%22from%22:%22now-1h%22,%22to%22:%22now%22%7D%7D%7D&orgId=1) page is showing the rate of samples being sent to Cortex.
224+
#### Configure Cortex Recording Rules and Alerting Rules (Optional)
225+
226+
We 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.
227+
228+
```sh
229+
# Port forward to the alertmanager to configure recording rules and alerts
230+
$ kubectl --namespace cortex port-forward svc/cortex-nginx 8080:80
231+
```
232+
233+
```sh
234+
# Configure recording rules for the cortex tenant
235+
$ cortextool rules sync rules.yaml alerts.yaml --id cortex --address http://localhost:8080
236+
```
205237

238+
#### Configure Cortex Alertmanager (Optional)
239+
240+
Cortex also comes with a multi-tenant Alertmanager. Let's load configuration for it to be able to view them in Grafana.
241+
242+
```sh
243+
# Configure alertmanager for the cortex tenant
244+
$ cortextool alertmanager load alertmanager-config.yaml --id cortex --address http://localhost:8080
245+
```
246+
247+
You can configure Alertmanager in [Grafana as well](http://localhost:3000/alerting/notifications?search=&alertmanager=Cortex%20Alertmanager).
248+
249+
There's a list of recording rules and alerts that should be visible in Grafana [here](http://localhost:3000/alerting/list?view=list&search=datasource:Cortex).
250+
251+
#### Explore
252+
253+
Grafana is configured to use Cortex as a data source. Grafana is also configured with [Cortex Dashboards](http://localhost:3000/dashboards?tag=cortex) to understand the state of the Cortex instance. The dashboards are generated from the cortex-jsonnet repository. There is a Makefile in the repository that can be used to update the dashboards.
254+
255+
```sh
256+
# Update the dashboards (optional)
257+
$ make
258+
```
206259

207260
If everything is working correctly, then the metrics seen in Grafana were successfully sent from Prometheus to Cortex
208-
via remote_write!
261+
via `remote_write`!
209262

210263
Other things to explore:
211264

265+
[Cortex](http://localhost:9009) - Administrative interface for Cortex
266+
212267
```sh
213-
# Port forward to the ingester to see the administrative interface for Cortex:
214-
$ kubectl --namespace cortex port-forward deploy/cortex-ingester 8080
268+
# Port forward to the ingester to see the administrative interface for Cortex
269+
$ kubectl --namespace cortex port-forward deploy/cortex-ingester 9009:8080
215270
```
216271

217-
- [Cortex Ingester](http://localhost:8080)
218-
- Try shutting down the [ingester](http://localhost:8080/ingester/shutdown) and see how it affects metric ingestion.
219-
- Restart ingester pod to bring the ingester back online, and see if Prometheus affected.
220-
- Does it affect the querying of metrics in Grafana? How many ingesters must be offline before it affects querying?
272+
- Try shutting down the ingester, and see how it affects metric ingestion.
273+
- Restart Cortex to bring the ingester back online, and see how Prometheus catches up.
274+
- Does it affect the querying of metrics in Grafana?
221275

276+
[Prometheus](http://localhost:9090) - Prometheus instance that is sending metrics to Cortex
222277

223278
```sh
224-
# Port forward to Prometheus to see the metrics that are being scraped:
279+
# Port forward to Prometheus to see the metrics that are being scraped
225280
$ kubectl --namespace cortex port-forward deploy/prometheus-server 9090
226281
```
282+
- Try querying the metrics in Prometheus.
283+
- Are they the same as what you see in Cortex?
227284

228-
- [Prometheus](http://localhost:9090) - Prometheus instance that is sending metrics to Cortex
229-
- Try querying the metrics in Prometheus.
230-
- Are they the same as what you see in Cortex?
285+
[Grafana](http://localhost:3000) - Grafana instance that is visualizing the metrics.
231286

232287
```sh
233-
# Port forward to Prometheus to see the metrics that are being scraped:
288+
# Port forward to Grafana to visualize
234289
$ kubectl --namespace cortex port-forward deploy/grafana 3000
235290
```
236291

237-
- [Grafana](http://localhost:3000) - Grafana instance that is visualizing the metrics.
238-
- Try creating a new dashboard and adding a new panel with a query to Cortex.
292+
- Try creating a new dashboard and adding a new panel with a query to Cortex.
239293

240294
### Clean up
241295

docs/getting-started/cortex-values.yaml

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ externalConfigSecretName: 'secret-with-config.yaml'
3636
externalConfigVersion: '0'
3737

3838
config:
39-
auth_enabled: false
39+
auth_enabled: true
4040
api:
4141
prometheus_http_prefix: '/prometheus'
4242
# -- Use GZIP compression for API responses. Some endpoints serve large YAML or JSON blobs
@@ -82,7 +82,7 @@ config:
8282
s3: &s3
8383
endpoint: seaweedfs.cortex.svc.cluster.local:8333
8484
region: local
85-
bucket_name: cortex-bucket
85+
bucket_name: cortex-blocks
8686
access_key_id: any
8787
secret_access_key: any
8888
insecure: true
@@ -93,9 +93,13 @@ config:
9393
bucket_index:
9494
enabled: true
9595
alertmanager_storage:
96-
s3: *s3
96+
s3:
97+
<<: *s3
98+
bucket_name: cortex-alertmanager
9799
ruler_storage:
98-
s3: *s3
100+
s3:
101+
<<: *s3
102+
bucket_name: cortex-ruler
99103
# -- https://cortexmetrics.io/docs/configuration/configuration-file/#store_gateway_config
100104
store_gateway:
101105
sharding_enabled: false
@@ -144,7 +148,7 @@ config:
144148
cluster:
145149
listen_address: '0.0.0.0:9094'
146150
# -- Enable the experimental alertmanager config api.
147-
enable_api: false
151+
enable_api: true
148152
external_url: '/api/prom/alertmanager'
149153
frontend:
150154
log_queries_longer_than: 10s
@@ -275,10 +279,14 @@ alertmanager:
275279
extraContainers: []
276280

277281
# -- Additional volumes to the cortex pod.
278-
extraVolumes: []
282+
extraVolumes:
283+
- name: tmp
284+
emptyDir: { }
279285

280286
# -- Extra volume mounts that will be added to the cortex container
281-
extraVolumeMounts: []
287+
extraVolumeMounts:
288+
- name: tmp
289+
mountPath: /tmp
282290

283291
# -- Additional ports to the cortex services. Useful to expose extra container ports.
284292
extraPorts: []
@@ -1423,11 +1431,7 @@ store_gateway:
14231431
path: /ready
14241432
port: http-metrics
14251433
scheme: HTTP
1426-
livenessProbe:
1427-
httpGet:
1428-
path: /ready
1429-
port: http-metrics
1430-
scheme: HTTP
1434+
livenessProbe: {}
14311435
readinessProbe:
14321436
httpGet:
14331437
path: /ready
@@ -1543,11 +1547,7 @@ compactor:
15431547
path: /ready
15441548
port: http-metrics
15451549
scheme: HTTP
1546-
livenessProbe:
1547-
httpGet:
1548-
path: /ready
1549-
port: http-metrics
1550-
scheme: HTTP
1550+
livenessProbe: {}
15511551
readinessProbe:
15521552
httpGet:
15531553
path: /ready
@@ -1670,4 +1670,5 @@ memcached-blocks-metadata:
16701670
memberlist:
16711671
service:
16721672
annotations: {}
1673-
labels: {}
1673+
labels: {}
1674+

docs/getting-started/grafana-values.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,15 @@ datasources:
605605
access: proxy
606606
isDefault: true
607607
editable: true
608+
jsonData:
609+
cacheLevel: None
610+
httpHeaderName1: X-Scope-OrgID
611+
httpMethod: POST
612+
prometheusType: Cortex
613+
prometheusVersion: 1.14.0
614+
timeInterval: 15s
615+
secureJsonData:
616+
httpHeaderValue1: cortex
608617
# - name: CloudWatch
609618
# type: cloudwatch
610619
# access: proxy
@@ -912,7 +921,7 @@ sidecar:
912921
# Sets the size limit of the alert sidecar emptyDir volume
913922
sizeLimit: {}
914923
dashboards:
915-
enabled: false
924+
enabled: true
916925
# Additional environment variables for the dashboards sidecar
917926
env: {}
918927
# Do not reprocess already processed unchanged resources on k8s API reconnect.

docs/getting-started/prometheus-values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ server:
249249
##
250250
remoteWrite:
251251
- url: http://cortex-nginx/api/v1/push
252+
headers:
253+
X-Scope-OrgID: "cortex"
252254
## https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_read
253255
##
254256
remoteRead: []

docs/getting-started/seaweedfs.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ spec:
4747
- "server"
4848
- "-s3"
4949
- "-s3.config=/workspace/seaweedfs-config.json"
50+
readinessProbe:
51+
httpGet:
52+
path: /status
53+
port: 8333
5054
ports:
5155
- containerPort: 8333
56+
name: seaweedfs
5257
volumeMounts:
5358
- name: seaweedfs-config
5459
mountPath: /workspace

0 commit comments

Comments
 (0)