Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: zsnmwy <35299017+zsnmwy@users.noreply.github.com>
  • Loading branch information
qmhu and zsnmwy authored May 17, 2022
1 parent 7c3447e commit 7cf0bbc
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 38 deletions.
4 changes: 2 additions & 2 deletions docs/tutorials/analytics-and-recommendation.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Two Recommendations are currently supported:

1. Users create `Analytics` object and config ResourceSelector to select resources to be analyzed. Multiple types of resource selection (based on Group,Kind, and Version) are supported.
2. Analyze each selected resource in parallel and try to execute analysis and give recommendation. Each analysis process is divided into two stages: inspecting and advising:
1. Inspecting: Filter resources that don't match the recommended conditions. For example, for hpa recommendation, the workload that have many not running pod is excluded
2. Advising: Analysis and calculate based on algorithm model then provide the recommendation result.
1. Inspecting: Filter resources that don't match the recommended conditions. For example, for hpa recommendation, the workload that has many not running pod is excluded
2. Advising: Analysis and calculation based on algorithm model then provide the recommendation result.
3. If you paas the above two stages, it will create `Recommendation` object and display the result in `recommendation.Status`
4. You can find the failure reasons from `analytics.status.recommendations`
5. Wait for the next analytics based on the interval
Expand Down
35 changes: 23 additions & 12 deletions docs/tutorials/hpa-recommendation.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
# HPA Recommendation

Using hpa recommendations, you can find resources in the cluster that are suitable for autoscaling, and use Crane's recommended result to create autoscaling object: [Effective HorizontalPodAutoscaler](tutorials/using-time-series-prediction.md)
Using hpa recommendations, you can find resources in the cluster that are suitable for autoscaling, and use Crane's recommended result to create an autoscaling object: [Effective HorizontalPodAutoscaler](using-time-series-prediction.md).

## Create HPA Analytics

Create an **Resource** `Analytics` to give recommendation for deployment: `nginx-deployment` as a sample.

```bash
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/nginx-deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/analytics-hpa.yaml
kubectl get analytics
```
=== "Main"

```bash
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/nginx-deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/analytics-hpa.yaml
kubectl get analytics
```

=== "Mirror"

```bash
kubectl apply -f https://finops.coding.net/p/gocrane/d/crane/git/raw/main/examples/analytics/nginx-deployment.yaml?download=false
kubectl apply -f https://finops.coding.net/p/gocrane/d/crane/git/raw/main/examples/analytics/analytics-hpa.yaml?download=false
kubectl get analytics
```


```yaml title="analytics-hpa.yaml"
apiVersion: analysis.crane.io/v1alpha1
Expand Down Expand Up @@ -39,15 +50,15 @@ NAME AGE
nginx-hpa 16m
```

You can get created recommendation from analytics status:
You can get created recommendations from analytics status:

```bash
kubectl get analytics nginx-hpa -o yaml
```

The output is similar to:

```yaml
```yaml hl_lines="32"
apiVersion: analysis.crane.io/v1alpha1
kind: Analytics
metadata:
Expand Down Expand Up @@ -154,10 +165,10 @@ status:

### Inspecting

1. Workload with low replicas: If the replicas is too low, may not be suitable for hpa recommendation. Associated configuration: ehpa.deployment-min-replicas | ehpa.statefulset-min-replicas | ehpa.workload-min-replicas
2. Workload with a certain percentage of not running pods: if the workload of Pod mostly can't run normally, may not be suitable for flexibility. Associated configuration: ehpa.pod-min-ready-seconds | ehpa.pod-available-ratio
3. Workload with low cpu usage: The low CPU usage workload means that there is no load pressure. In this case, we can't estimate it. Associated configuration: ehpa.min-cpu-usage-threshold
4. Workload with low fluctuation of cpu usage: dividing of the maximum and minimum usage is defined as the fluctuation rate. If the fluctuation rate is too low, the workload will not benefit much from hpa. Associated configuration: ehpa.fluctuation-threshold
1. Workload with low replicas: If the replicas is too low, may not be suitable for hpa recommendation. Associated configuration: `ehpa.deployment-min-replicas` | `ehpa.statefulset-min-replicas` | `ehpa.workload-min-replicas`
2. Workload with a certain percentage of not running pods: if the workload of Pod mostly can't run normally, may not be suitable for flexibility. Associated configuration: `ehpa.pod-min-ready-seconds` | `ehpa.pod-available-ratio`
3. Workload with low CPU usage: The low CPU usage workload means that there is no load pressure. In this case, we can't estimate it. Associated configuration: `ehpa.min-cpu-usage-threshold`
4. Workload with low fluctuation of CPU usage: dividing of the maximum and minimum usage is defined as the fluctuation rate. If the fluctuation rate is too low, the workload will not benefit much from hpa. Associated configuration: `ehpa.fluctuation-threshold`

### Advising

Expand Down
31 changes: 21 additions & 10 deletions docs/tutorials/hpa-recommendation.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@

创建一个**弹性分析** `Analytics`,这里我们通过实例 deployment: `nginx` 作为一个例子

```bash
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/nginx-deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/analytics-hpa.yaml
kubectl get analytics
```
=== "Main"

```bash
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/nginx-deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/analytics-hpa.yaml
kubectl get analytics
```

=== "Mirror"

```bash
kubectl apply -f https://finops.coding.net/p/gocrane/d/crane/git/raw/main/examples/analytics/nginx-deployment.yaml?download=false
kubectl apply -f https://finops.coding.net/p/gocrane/d/crane/git/raw/main/examples/analytics/analytics-hpa.yaml?download=false
kubectl get analytics
```


```yaml title="analytics-hpa.yaml"
apiVersion: analysis.crane.io/v1alpha1
Expand Down Expand Up @@ -47,7 +58,7 @@ kubectl get analytics nginx-hpa -o yaml

结果如下:

```yaml
```yaml hl_lines="32"
apiVersion: analysis.crane.io/v1alpha1
kind: Analytics
metadata:
Expand Down Expand Up @@ -154,10 +165,10 @@ status:
### 筛选阶段
1. 低副本数的工作负载: 过低的副本数可能弹性需求不高,关联配置: ehpa.deployment-min-replicas | ehpa.statefulset-min-replicas | ehpa.workload-min-replicas
2. 存在一定比例非 Running Pod 的工作负载: 如果工作负载的 Pod 大多不能正常运行,可能不适合弹性,关联配置: ehpa.pod-min-ready-seconds | ehpa.pod-available-ratio
3. 低 CPU 使用量的工作负载: 过低使用量的工作负载意味着没有业务压力,此时通过使用率推荐弹性不准,关联配置: ehpa.min-cpu-usage-threshold
4. CPU 使用量的波动率过低: 使用量的最大值和最小值的倍数定义为波动率,波动率过低的工作负载通过弹性降本的收益不大,关联配置: ehpa.fluctuation-threshold
1. 低副本数的工作负载: 过低的副本数可能弹性需求不高,关联配置: `ehpa.deployment-min-replicas` | `ehpa.statefulset-min-replicas` | `ehpa.workload-min-replicas`
2. 存在一定比例非 Running Pod 的工作负载: 如果工作负载的 Pod 大多不能正常运行,可能不适合弹性,关联配置: `ehpa.pod-min-ready-seconds` | `ehpa.pod-available-ratio`
3. 低 CPU 使用量的工作负载: 过低使用量的工作负载意味着没有业务压力,此时通过使用率推荐弹性不准,关联配置: `ehpa.min-cpu-usage-threshold`
4. CPU 使用量的波动率过低: 使用量的最大值和最小值的倍数定义为波动率,波动率过低的工作负载通过弹性降本的收益不大,关联配置: `ehpa.fluctuation-threshold`

### 推荐

Expand Down
26 changes: 19 additions & 7 deletions docs/tutorials/resource-recommendation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ Resource recommendation allows you to obtain recommended values for resources in

Create an **Resource** `Analytics` to give recommendation for deployment: `nginx-deployment` as a sample.

```bash
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/nginx-deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/analytics-resource.yaml
kubectl get analytics -n crane-system
```

=== "Main"

```bash
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/nginx-deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/analytics-resource.yaml
kubectl get analytics -n crane-system
```

=== "Mirror"

```bash
kubectl apply -f https://finops.coding.net/p/gocrane/d/crane/git/raw/main/examples/analytics/nginx-deployment.yaml?download=false
kubectl apply -f https://finops.coding.net/p/gocrane/d/crane/git/raw/main/examples/analytics/analytics-resource.yaml?download=false
kubectl get analytics -n crane-system
```


```yaml title="analytics-resource.yaml" hl_lines="7 24 11-14 28-31"
apiVersion: analysis.crane.io/v1alpha1
Expand Down Expand Up @@ -43,7 +55,7 @@ kubectl get analytics nginx-resource -o yaml

The output is similar to:

```yaml
```yaml hl_lines="27"
apiVersion: analysis.crane.io/v1alpha1
kind: Analytics
metadata:
Expand Down Expand Up @@ -85,7 +97,7 @@ The recommendation name presents on `status.recommendations[0].name`. Then you c
## Recommendation: Analytics result

```bash
kubectl get recommend -n crane-system craned-resource-resource-j7shb -o yaml
kubectl get recommend -n crane-system nginx-resource-resource-w45nq -o yaml
```

The output is similar to:
Expand Down
24 changes: 18 additions & 6 deletions docs/tutorials/resource-recommendation.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@

创建一个**资源分析** `Analytics`,这里我们通过实例 deployment: `nginx` 作为一个例子

```bash
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/nginx-deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/analytics-resource.yaml
kubectl get analytics
```

=== "Main"

```bash
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/nginx-deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/gocrane/crane/main/examples/analytics/analytics-resource.yaml
kubectl get analytics
```

=== "Mirror"

```bash
kubectl apply -f https://finops.coding.net/p/gocrane/d/crane/git/raw/main/examples/analytics/nginx-deployment.yaml?download=false
kubectl apply -f https://finops.coding.net/p/gocrane/d/crane/git/raw/main/examples/analytics/analytics-resource.yaml?download=false
kubectl get analytics
```


```yaml title="analytics-resource.yaml"
apiVersion: analysis.crane.io/v1alpha1
Expand Down Expand Up @@ -43,7 +55,7 @@ kubectl get analytics nginx-resource -o yaml

结果如下:

```yaml
```yaml hl_lines="27"
apiVersion: analysis.crane.io/v1alpha1
kind: Analytics
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ status:
```

原因:不是所有的工作负载的 CPU 使用率都是可预测的,当无法预测时就会显示以上错误。
reason: Not all workload's cpu metric are predictable, if predict your workload failed, it will show above errors.

解决方案:

- 等一段时间再看。预测算法 `DSP` 需要一定时间的数据才能进行预测。希望了解算法细节的可以查看算法的文档。
- EffectiveHorizontalPodAutoscaler 提供一种保护机制,当预测失效时依然能通过实际的 CPU 使用率工作。

0 comments on commit 7cf0bbc

Please sign in to comment.