Skip to content

Commit

Permalink
preinstall pv
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhu committed Jun 14, 2023
1 parent 19b8464 commit 39fde76
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 16 deletions.
25 changes: 25 additions & 0 deletions pkg/server/handler/clusters/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ spec:
- name: Service
`

const RecommendationRulePVsName = "persistentvolumes-rule"
const RecommendationRulePVsYAML = `
apiVersion: analysis.crane.io/v1alpha1
kind: RecommendationRule
metadata:
name: persistentvolumes-rule
labels:
analysis.crane.io/recommendation-rule-preinstall: "true"
spec:
runInterval: 24h # 每24h运行一次
resourceSelectors: # 资源的信息
- kind: PersistentVolume
apiVersion: v1
namespaceSelector:
any: true # 扫描所有namespace
recommenders:
- name: Volume
`

type AddClustersRequest struct {
Clusters []*store.Cluster `json:"clusters"`
}
Expand Down Expand Up @@ -195,6 +214,12 @@ func (ch *ClusterHandler) AddClusters(c *gin.Context) {
ginwrapper.WriteResponse(c, err, nil)
return
}

err = ch.upsertRecommendationRule(RecommendationRulePVsName, RecommendationRulePVsYAML)
if err != nil {
ginwrapper.WriteResponse(c, err, nil)
return
}
} else if err != nil {
ginwrapper.WriteResponse(c, err, nil)
return
Expand Down
Binary file added site/.DS_Store
Binary file not shown.
50 changes: 43 additions & 7 deletions site/content/en/docs/Tutorials/Recommendation/pv-recommendation.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,60 @@
---
title: "PV 推荐"
description: "PV 推荐功能介绍"
weight: 15
title: "PV Recommendation"
description: "Introduce for PV Recommendation"
weight: 17
---

Service 推荐通过扫描集群中 Service 的运行状况,帮助用户找到闲置的 Kubernetes Service
PV 推荐通过扫描集群中 PV 的运行状况,帮助用户找到闲置的 Kubernetes PV

## 动机

通常在 Kubernetes 中我们会使用 Service + Workload 来自动创建和管理负载均衡并 将负载均衡挂载到应用上,在日常的运营中难免会出现空闲和低利用率的负载均衡,浪费了大量成本,Service 推荐尝试帮助用户找到这部分 Service 来实现成本优化。
通常在 Kubernetes 中我们会使用 PV + Workload 来自动创建和管理存储卷并将存储卷挂载到应用上,在日常的运营中难免会出现空闲或者空跑的存储卷,浪费了大量成本, PV 推荐尝试帮助用户找到这部分 PV 来实现成本优化。

## 推荐示例

```yaml

apiVersion: analysis.crane.io/v1alpha1
kind: Recommendation
metadata:
annotations:
analysis.crane.io/last-start-time: "2023-06-14 08:55:25"
analysis.crane.io/message: Success
analysis.crane.io/run-number: "653"
labels:
analysis.crane.io/recommendation-rule-name: persistentvolumes-rule
analysis.crane.io/recommendation-rule-recommender: Volume
analysis.crane.io/recommendation-rule-uid: 39d30abe-4c7f-4e65-b961-b00ec7776b45
analysis.crane.io/recommendation-target-kind: PersistentVolume
analysis.crane.io/recommendation-target-name: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
analysis.crane.io/recommendation-target-namespace: ""
analysis.crane.io/recommendation-target-version: v1
name: persistentvolumes-rule-volume-5r9zn
namespace: crane-system
ownerReferences:
- apiVersion: analysis.crane.io/v1alpha1
blockOwnerDeletion: false
controller: false
kind: RecommendationRule
name: persistentvolumes-rule
uid: 39d30abe-4c7f-4e65-b961-b00ec7776b45
spec:
adoptionType: StatusAndAnnotation
completionStrategy:
completionStrategyType: Once
targetRef:
apiVersion: v1
kind: PersistentVolume
name: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
type: Volume
status:
action: Delete
description: It is an Orphan Volumes
lastUpdateTime: "2023-06-14T08:55:25Z"
```

在该示例中:

- 推荐的 TargetRef 指向了 PV:
- 推荐的 TargetRef 指向了 PV: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
- 推荐类型为 PV 推荐
- action 是 Delete,这里只是给出建议

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "闲置节点推荐"
description: "闲置节点推荐功能介绍"
weight: 15
title: "Service Recommendation"
description: "Introduce for Service Recommendation"
weight: 16
---

Service 推荐通过扫描集群中 Service 的运行状况,帮助用户找到闲置的 Kubernetes Service。
Expand Down
42 changes: 39 additions & 3 deletions site/content/zh/docs/Tutorials/Recommendation/pv-recommendation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "PV 推荐"
description: "PV 推荐功能介绍"
weight: 15
weight: 17
---

PV 推荐通过扫描集群中 PV 的运行状况,帮助用户找到闲置的 Kubernetes PV。
Expand All @@ -13,12 +13,48 @@ PV 推荐通过扫描集群中 PV 的运行状况,帮助用户找到闲置的
## 推荐示例

```yaml

apiVersion: analysis.crane.io/v1alpha1
kind: Recommendation
metadata:
annotations:
analysis.crane.io/last-start-time: "2023-06-14 08:55:25"
analysis.crane.io/message: Success
analysis.crane.io/run-number: "653"
labels:
analysis.crane.io/recommendation-rule-name: persistentvolumes-rule
analysis.crane.io/recommendation-rule-recommender: Volume
analysis.crane.io/recommendation-rule-uid: 39d30abe-4c7f-4e65-b961-b00ec7776b45
analysis.crane.io/recommendation-target-kind: PersistentVolume
analysis.crane.io/recommendation-target-name: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
analysis.crane.io/recommendation-target-namespace: ""
analysis.crane.io/recommendation-target-version: v1
name: persistentvolumes-rule-volume-5r9zn
namespace: crane-system
ownerReferences:
- apiVersion: analysis.crane.io/v1alpha1
blockOwnerDeletion: false
controller: false
kind: RecommendationRule
name: persistentvolumes-rule
uid: 39d30abe-4c7f-4e65-b961-b00ec7776b45
spec:
adoptionType: StatusAndAnnotation
completionStrategy:
completionStrategyType: Once
targetRef:
apiVersion: v1
kind: PersistentVolume
name: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
type: Volume
status:
action: Delete
description: It is an Orphan Volumes
lastUpdateTime: "2023-06-14T08:55:25Z"
```

在该示例中:

- 推荐的 TargetRef 指向了 PV:
- 推荐的 TargetRef 指向了 PV: pvc-6ce24277-24e9-4fcf-8e8a-f9bdb5694134
- 推荐类型为 PV 推荐
- action 是 Delete,这里只是给出建议

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "闲置节点推荐"
description: "闲置节点推荐功能介绍"
weight: 15
title: "Service 推荐"
description: "Service 推荐功能介绍"
weight: 16
---

Service 推荐通过扫描集群中 Service 的运行状况,帮助用户找到闲置的 Kubernetes Service。
Expand Down
Binary file added site/training.zip
Binary file not shown.

0 comments on commit 39fde76

Please sign in to comment.