我是Kubernetes的新手,并计划将我的一些ECS服务转移到EKS上。在我目前的自动缩放算法中,除了CPU、内存和其他一些东西外,我还使用了传入请求的速率。在Kubernetes中,我如何利用传入请求的速率来自定义自动伸缩?
您可以使用Prometheus适配器和HPA,以根据传入请求或您想要的其他指标扩展部署。
https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/docs/walkthrough.md
也可以查看:https://github.com/zalando-incubator/kube-metrics-adapter
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
annotations:
# metric-config.<metricType>.<metricName>.<collectorType>/<configKey>
metric-config.pods.requests-per-second.json-path/json-key: "$.http_server.rps"
metric-config.pods.requests-per-second.json-path/path: /metrics
metric-config.pods.requests-per-second.json-path/port: "9090"
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
minReplicas: 1
maxReplicas: 10
metrics:
- type: Pods
pods:
metric:
name: requests-per-second
target:
averageValue: 1k
type: AverageValue