我正在尝试使用自动缩放场景(目前使用 microk8s 单节点个人集群)。
基本的 CPU 扩展工作正常。
对于更复杂的场景,我尝试遵循 https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-multiple-metrics- 的指南and-custom-metrics 但我无法弄清楚如何/在哪里定义/记录可能的 pod 指标/对象指标。例如,..“每秒数据包”记录在哪里。
我可以通过 kubectl 进行导航或手动执行 REST API,但必须有更好的方法。
谢谢
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: php-apache
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: php-apache
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: AverageUtilization
averageUtilization: 50
- type: Pods
pods:
metric:
name: packets-per-second ====> where is this name defined/documented ?
targetAverageValue: 1k
- type: Object
object:
metric:
name: requests-per-second ====> where is this name defined/documented ?
describedObject:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
name: main-route
target:
kind: Value
value: 10k
ResourceMetric 中的 CPU 或内存使用情况由 kubelet 提供并由 metric-server 收集
但是对于 packets-per-second
和 requests-per-second
一些流行的自定义指标 API 列于https://github.com/kubernetes/metrics/blob/release-1.22/IMPLMENTATIONS.md
下面的 GitHub 项目提供了大量有关使用 Prometheus 提供的自定义指标在 Kubernetes 中自动缩放 Pod 的信息。