Skip to content

Commit 2ac3c63

Browse files
authored
Merge pull request honojs#603 from B1F030/doc-translate
doc: translate zh/tutorials/autoscaling-with-custom-metrics
2 parents 7fd0868 + 17b8476 commit 2ac3c63

3 files changed

Lines changed: 153 additions & 118 deletions

File tree

docs/tutorials/autoscaling-with-custom-metrics.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ spec:
7474
7575
### prometheus and prometheus-adapter have been installed in member clusters
7676
77-
You need to install `prometheus` and `prometheus-adapter` for member clusters to provider the custom metrics.
77+
You need to install `prometheus` and `prometheus-adapter` for member clusters to provide the custom metrics.
7878
You can install it by running the following in member clusters:
7979
```sh
8080
git clone https://github.com/prometheus-operator/kube-prometheus.git
@@ -88,7 +88,7 @@ kubectl apply -f manifests/
8888
```
8989

9090
You can verify the installation by the following command:
91-
```
91+
```sh
9292
kubectl --kubeconfig=/root/.kube/members.config --context=member1 get po -nmonitoring
9393
NAME READY STATUS RESTARTS AGE
9494
alertmanager-main-0 2/2 Running 0 30h
@@ -112,10 +112,7 @@ You need to install `karmada-metrics-adapter` in Karmada control plane to provid
112112
hack/deploy-metrics-adapter.sh ${host_cluster_kubeconfig} ${host_cluster_context} ${karmada_apiserver_kubeconfig} ${karmada_apiserver_context_name}
113113
```
114114

115-
If you use the `hack/local-up-karmada.sh` script to deploy Karmada, you can run following command to deploy `karmada-metrics-adapter`:
116-
```sh
117-
hack/deploy-metrics-adapter.sh $HOME/.kube/karmada.config karmada-host $HOME/.kube/karmada.config karmada-apiserver
118-
```
115+
If you use the `hack/local-up-karmada.sh` script to deploy Karmada, `karmada-metrics-adapter` will be installed by default.
119116

120117
## Deploy workload in `member1` and `member2` cluster
121118

@@ -222,13 +219,14 @@ spec:
222219
- port: http
223220
```
224221

225-
```
222+
```sh
226223
kubectl create -f sample-app.monitor.yaml
227224
```
228225

229226
Now, you should see your metrics (http_requests_total) appear in your Prometheus instance. Look them up via the dashboard, and make sure they have the namespace and pod labels. If not, check the labels on the service monitor match the ones on the Prometheus CRD.
230227

231228
## Launch you adapter in `member1` and `member2` cluster
229+
232230
After you deploy `prometheus-adapter`, you need to update to the adapter config which is necessary in order to expose custom metrics.
233231

234232
```yaml
@@ -255,13 +253,13 @@ data:
255253
)
256254
```
257255

258-
```
256+
```sh
259257
$ kubectl apply -f prom-adapter.config.yaml
260258
# Restart prom-adapter pods
261259
$ kubectl rollout restart deployment prometheus-adapter -n monitoring
262260
```
263261

264-
## Registry metrics API in `member1` and `member2` cluster
262+
## Register metrics API in `member1` and `member2` cluster
265263

266264
You also need to register the custom metrics API with the API aggregator (part of the main Kubernetes API server). For that you need to create an APIService resource.
267265

@@ -281,20 +279,40 @@ spec:
281279
versionPriority: 100
282280
```
283281

284-
```
282+
```sh
285283
$ kubectl create -f api-service.yaml
286284
```
287285

288286
The API is registered as `custom.metrics.k8s.io/v1beta2`, and you can use the following command to verify:
289287

290-
```
288+
```sh
291289
$ kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta2/namespaces/default/pods/*/http_requests?selector=app%3Dsample-app"
292290
```
293291

294292
The output is similar to:
295293

296-
```
297-
{"kind":"MetricValueList","apiVersion":"custom.metrics.k8s.io/v1beta2","metadata":{},"items":[{"describedObject":{"kind":"Pod","namespace":"default","name":"sample-app-9b7d8c9f5-9lw6b","apiVersion":"/v1"},"metric":{"name":"http_requests","selector":null},"timestamp":"2023-06-14T09:09:54Z","value":"66m"}]}
294+
```json
295+
{
296+
"kind": "MetricValueList",
297+
"apiVersion": "custom.metrics.k8s.io/v1beta2",
298+
"metadata": {},
299+
"items": [
300+
{
301+
"describedObject": {
302+
"kind": "Pod",
303+
"namespace": "default",
304+
"name": "sample-app-9b7d8c9f5-9lw6b",
305+
"apiVersion": "/v1"
306+
},
307+
"metric": {
308+
"name": "http_requests",
309+
"selector": null
310+
},
311+
"timestamp": "2023-06-14T09:09:54Z",
312+
"value": "66m"
313+
}
314+
]
315+
}
298316
```
299317

300318
If `karmada-metrics-adapter` is installed successfully, you can also verify it with the above command in Karmada control plane.
@@ -400,7 +418,7 @@ derived-sample-app member1 ClusterIP 10.11.59.213 <none> 80/T
400418

401419
In order to do http requests, here you can use `hey`.
402420
* Download `hey` and copy it to kind cluster container.
403-
```
421+
```sh
404422
$ wget https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64
405423
$ chmod +x hey_linux_amd64
406424
$ docker cp hey_linux_amd64 member1-control-plane:/usr/local/bin/hey
@@ -422,7 +440,7 @@ $ docker cp hey_linux_amd64 member1-control-plane:/usr/local/bin/hey
422440
derived-sample-app member1 ClusterIP 10.11.59.213 <none> 80/TCP 20m Y
423441
```
424442

425-
* Request multi-cluster service with hey to increase the nginx pods' CPU usage.
443+
* Request multi-cluster service with hey to increase the nginx pods' custom metrics(http_requests_total).
426444
```sh
427445
$ docker exec member1-control-plane hey -c 1000 -z 1m http://10.11.59.213/metrics
428446
```

0 commit comments

Comments
 (0)