Skip to content

Commit

Permalink
Merge pull request #94 from qmhu/0.1.0-windup
Browse files Browse the repository at this point in the history
0.1.0 windup
  • Loading branch information
qmhu committed Jan 10, 2022
2 parents 0fe6714 + 572f692 commit 36026e9
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 180 deletions.
29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,31 @@ Crane is composed of the following components:
#### Installing prometheus components with helm chart

> Note:
> If you already deployed prometheus, kube-state-metric, prometheus-node-exporter, then you can skip this step.
> If you already deployed prometheus, prometheus-node-exporter, then you can skip this step.
Crane use prometheus to be the default metric provider. Using following command to install prometheus with the release name `[RELEASE_NAME]`. It will also install dependent chart: kube-state-metric.
Export the following env if you want to use default settings, or specify customized value if you want to customize the installation.

```console
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install [RELEASE_NAME] -n [NAMESPACE] --create-namespace prometheus-community/prometheus
export NAMESPACE=monitoring
export RELEASE_NAME=myprometheus
```

Using following command to install prometheus-node-exporter with another release name `[NODE_EXPORTER_RELEASE_NAME]`.
Crane use prometheus to be the default metric provider. Using following command to install prometheus components.

```console
helm install [NODE_EXPORTER_RELEASE_NAME] -n [NAMESPACE] --create-namespace prometheus-community/prometheus-node-exporter
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

helm install $RELEASE_NAME -n $NAMESPACE --set kubeStateMetrics.enabled=false --set pushgateway.enabled=false --set alertmanager.enabled=false --set server.persistentVolume.enabled=false --create-namespace prometheus-community/prometheus
```

#### Configure Prometheus Address

The following command will configure your prometheus http address for crane, please change `YOUR_PROMETHEUS` to actual Prometheus address. If you're following above guide to install prometheus with helm chart then **YOUR_PROMETHEUS** would be: `http:\/\/[RELEASE_NAME]-prometheus-server.[NAMESPACE].svc.cluster.local`
The following command will configure prometheus http address for crane. Specify `CUSTOMIZE_PROMETHEUS` if you have existing prometheus server.

```console
PROMETHEUS_ADDRESS="YOUR_PROMETHEUS" && sed -i '' "s/PROMETHEUS_ADDRESS/${YOUR_ADDRESS}/" deploy/craned/deployment.yaml
export CUSTOMIZE_PROMETHEUS=
if [ ! $CUSTOMIZE_PROMETHEUS ]; then sed -i '' "s/PROMETHEUS_ADDRESS/http:\/\/${RELEASE_NAME}-server.${NAMESPACE}.svc.cluster.local/" deploy/craned/deployment.yaml ; else sed -i '' "s/PROMETHEUS_ADDRESS/${CUSTOMIZE_PROMETHEUS}/" deploy/craned/deployment.yaml ; fi
```

#### Deploying Crane
Expand All @@ -119,11 +122,3 @@ kubectl apply -f deploy/manifests
kubectl apply -f deploy/craned
kubectl apply -f deploy/metric-adapter
```

#### Deploying Crane-agent

If you want to try `QoS Ensurance`, then deploy `Crane-agent` by apply YAML declaration which will create a DaemonSet in your cluster.

```console
kubectl apply -f deploy/crane-agent
```
10 changes: 2 additions & 8 deletions cmd/craned/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app
import (
"context"
"flag"
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -33,7 +32,6 @@ import (
"github.com/gocrane/crane/pkg/controller/timeseriesprediction"
"github.com/gocrane/crane/pkg/features"
"github.com/gocrane/crane/pkg/known"
"github.com/gocrane/crane/pkg/log"
"github.com/gocrane/crane/pkg/metrics"
"github.com/gocrane/crane/pkg/prediction"
"github.com/gocrane/crane/pkg/prediction/dsp"
Expand Down Expand Up @@ -105,7 +103,7 @@ func Run(ctx context.Context, opts *options.Options) error {
}

if opts.WebhookConfig.Enabled {
initializationWebhooks(mgr, opts)
initializationWebhooks(mgr)
}
initializationControllers(ctx, mgr, opts)
klog.Info("Starting crane manager")
Expand All @@ -126,9 +124,7 @@ func initializationMetricCollector(mgr ctrl.Manager) {
metrics.CustomCollectorRegister(metrics.NewTspMetricCollector(mgr.GetClient()))
}

func initializationWebhooks(mgr ctrl.Manager, opts *options.Options) {
log.Logger().Info(fmt.Sprintf("opts %v", opts))

func initializationWebhooks(mgr ctrl.Manager) {
if certDir := os.Getenv("WEBHOOK_CERT_DIR"); len(certDir) > 0 {
mgr.GetWebhookServer().CertDir = certDir
}
Expand All @@ -144,7 +140,6 @@ func initializationControllers(ctx context.Context, mgr ctrl.Manager, opts *opti
nodeResource := utilfeature.DefaultFeatureGate.Enabled(features.CraneNodeResource)
clusterNodePrediction := utilfeature.DefaultFeatureGate.Enabled(features.CraneClusterNodePrediction)
analysis := utilfeature.DefaultMutableFeatureGate.Enabled(features.CraneAnalysis)
// todo: add more features
timeseriespredict := utilfeature.DefaultFeatureGate.Enabled(features.CraneTimeSeriesPrediction)

discoveryClientSet, err := discovery.NewDiscoveryClientForConfig(mgr.GetConfig())
Expand Down Expand Up @@ -245,7 +240,6 @@ func initializationControllers(ctx context.Context, mgr ctrl.Manager, opts *opti
if analysis {
if err := (&analytics.Controller{
Client: mgr.GetClient(),
Logger: log.Logger().WithName("analytics-controller"),
Scheme: mgr.GetScheme(),
RestMapper: mgr.GetRESTMapper(),
Recorder: mgr.GetEventRecorderFor("analytics-controller"),
Expand Down
25 changes: 24 additions & 1 deletion deploy/craned/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,28 @@ spec:
operator: Exists
containers:
- name: craned
image: docker.io/gocrane/craned
image: docker.io/gocrane/craned:v0.1.0
imagePullPolicy: IfNotPresent
command:
- /craned
- --prometheus-address=PROMETHEUS_ADDRESS
- --feature-gates=Analysis=true,TimeSeriesPrediction=true,Autoscaling=true
- --recommendation-config-file=/tmp/recommendation-config/config_set.yaml
- -v=4
volumeMounts:
- mountPath: /tmp/k8s-webhook-server/serving-certs
name: cert
readOnly: true
- name: config
mountPath: /tmp/recommendation-config
volumes:
- name: cert
secret:
defaultMode: 420
secretName: webhook-server-tls
- name: config
configMap:
name: recommendation-config
---
apiVersion: v1
data:
Expand All @@ -60,3 +67,19 @@ metadata:
name: webhook-server-tls
namespace: crane-system
type: kubernetes.io/tls

---

apiVersion: v1
kind: ConfigMap
metadata:
name: recommendation-config
namespace: crane-system
data:
config_set.yaml: |-
apiVersion: analysis.crane.io/v1alpha1
kind: ConfigSet
configs:
- targets: []
properties:
cpu-request-percentile: "0.98"
66 changes: 0 additions & 66 deletions deploy/manifests/analysis.crane.io_configsets.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion deploy/metric-adapter/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
serviceAccountName: metric-adapter
containers:
- name: metric-adapter
image: docker.io/gocrane/metric-adapter
image: docker.io/gocrane/metric-adapter:v0.1.0
imagePullPolicy: IfNotPresent
args:
- /metric-adapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
name: php-apache
minReplicas: 1 # MinReplicas is the lower limit replicas to the scale target which the autoscaler can scale down to.
maxReplicas: 10 # MaxReplicas is the upper limit replicas to the scale target which the autoscaler can scale up to.
scaleStrategy: Auto # ScaleStrategy indicate the strategy to scaling target, value can be "Auto" and "Manual".
scaleStrategy: Auto # ScaleStrategy indicate the strategy to scaling target, value can be "Auto" and "Preview".
# Metrics contains the specifications for which to use to calculate the desired replica count.
metrics:
- type: Resource
Expand All @@ -45,7 +45,7 @@ spec:
* spec.scaleTargetRef defines the reference to the workload that should be scaled.
* spec.minReplicas is the lower limit replicas to the scale target which the autoscaler can scale down to.
* spec.maxReplicas is the upper limit replicas to the scale target which the autoscaler can scale up to.
* spec.metrics indicate the strategy to scaling target, value can be "Auto" and "Manual".
* spec.metrics indicate the strategy to scaling target, value can be "Auto" and "Preview".
* spec.metrics contains the specifications for which to use to calculate the desired replica count. Please refer to the details:
* spec.prediction defines configurations for predict resources.If unspecified, defaults don't enable prediction.

Expand Down Expand Up @@ -138,22 +138,24 @@ We can see significant improvement with EffectiveHorizontalPodAutoscaler:
* Fewer replicas changes than HorizontalPodAutoscaler

### ScaleStrategy
EffectiveHorizontalPodAutoscaler provides two strategies for scaling: `Auto` and `Manual`. User can change the strategy at runtime, and it will take effect on the fly.
EffectiveHorizontalPodAutoscaler provides two strategies for scaling: `Auto` and `Preview`. User can change the strategy at runtime, and it will take effect on the fly.

#### Auto
Auto strategy achieves automatic scaling based on metrics. It is the default strategy. With this strategy, EffectiveHorizontalPodAutoscaler will create and control a HorizontalPodAutoscaler instance in backend. We don't recommend explicit configuration on the underlying HorizontalPodAutoscaler because it will be overridden by EffectiveHPAController. If user delete EffectiveHorizontalPodAutoscaler, HorizontalPodAutoscaler will be cleaned up too.

#### Manual
Manual strategy means user can specify replicas of target. User can switch from default strategy to this one by applying `spec.scaleStrategy` to `Manual`. It will take effect immediately, During the switch, EffectiveHPAController will disable HorizontalPodAutoscaler if exists and scale the target to the value `spec.specificReplicas`, if user not set `spec.specificReplicas`, when ScaleStrategy is change to Manual, it will just stop scaling.
#### Preview
Preview strategy means EffectiveHorizontalPodAutoscaler won't change target's replicas automatically, so you can preview the calculated replicas and control target's replicas by themselves. User can switch from default strategy to this one by applying `spec.scaleStrategy` to `Preview`. It will take effect immediately, During the switch, EffectiveHPAController will disable HorizontalPodAutoscaler if exists and scale the target to the value `spec.specificReplicas`, if user not set `spec.specificReplicas`, when ScaleStrategy is change to Preview, it will just stop scaling.

A sample manual configuration looks like following:
A sample preview configuration looks like following:
```yaml
apiVersion: autoscaling.crane.io/v1alpha1
kind: EffectiveHorizontalPodAutoscaler
spec:
scaleStrategy: Auto # ScaleStrategy indicate the strategy to scaling target, value can be "Auto" and "Manual".
specificReplicas: 5 # SpecificReplicas specify the target replicas.
scaleStrategy: Preview # ScaleStrategy indicate the strategy to scaling target, value can be "Auto" and "Preview".
specificReplicas: 5 # SpecificReplicas specify the target replicas.
status:
expectReplicas: 4 # expectReplicas is the calculated replicas that based on prediction metrics or spec.specificReplicas.
currentReplicas: 4 # currentReplicas is actual replicas from target
```

### HorizontalPodAutoscaler compatible
Expand Down
6 changes: 6 additions & 0 deletions examples/config_set.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: analysis.crane.io/v1alpha1
kind: ConfigSet
configs:
- targets: []
properties:
cpu-request-percentile: "0.98"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.17
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-echarts/go-echarts/v2 v2.2.4
github.com/go-logr/logr v0.4.0
github.com/gocrane/api v0.0.0-20220101093604-2129a9ce85e3
github.com/google/go-cmp v0.5.6 // indirect
github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12
Expand Down Expand Up @@ -47,6 +46,7 @@ require (
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
Expand Down
Loading

0 comments on commit 36026e9

Please sign in to comment.