For scaling pods depending on custom metrics you can also use the Horizontal Pod Autoscaler (HPA).
To make your custom metric available to the HPA, you need to make them available in the API Server. This can be done by
- Collecting your custom metrics with Prometheus
- Attaching your prometheus metrics to the Metrics Server with [Prometheus Adapter](https://github.com/DirectXMan12/ k8s-prometheus-adapter)
- Configure your HPA to use the custom metric for scaling
![custom-metric-scaling.png](custom metric scaling)
For more information see: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-multiple-metrics-and-custom-metrics
# TODO: Try out with helm chart
kubectl apply -f custom-metric-scaling
helm install -f metric-config.yaml --name prometheus-adapter-release stable/prometheus-adapter
helm install -f metric-config.yaml --name prometheus-adapter-release stable/prometheus-adapter
Example:
type: Pods
pods:
metric:
name: packets-per-second
target:
type: AverageValue
averageValue: 1k
See: https://github.com/Azure/azure-k8s-metrics-adapter implemented with https://github.com/kubernetes-incubator/custom-metrics-apiserver
https://github.com/DirectXMan12/k8s-prometheus-adapter/blob/master/docs/walkthrough.md