Custom metrics için Prometheus ve prometheus-adapter kuruluyor. Açıklaması şöyle
In order to scale based on custom metrics we need to have two components:- One that collects metrics from our applications and stores them to Prometheus time series database.
- The second one that extends the Kubernetes Custom Metrics API with the metrics supplied by a collector, the k8s-prometheus-adapter. This is an implementation of the custom metrics API that attempts to support arbitrary metrics.
Yani özel bir kurulum yapmak gerekiyor.
Custom Metric Değerlerini Görmek
Örnek
Şöyle yaparız
https://<apiserver_ip>/apis/custom-metrics.metrics.k8s.io/v1beta1\ /namespaces/default/pods/sample-metrics-app/http_requests
Açıklaması şöyle
So When you visit the above URL, the Custom Metrics API Server will go to Prometheus to query the value of the http_requests metric of the Pod named sample-metrics-app, and then return in a fixed format. And of course, the http_requests value is already collected by Prometheus.
Örnek
Şöyle yaparız. scaleTargetRef alanında Deployment ismi ve kaç tane pod istendiği belirtiliyor. İstenen sayı 3 -15 arasında. Daha sonra metric alanında Burada - type: Pods kullanılıyor ve metric belirtiliyorapiVersion: autoscaling/v2beta1kind: HorizontalPodAutoscalermetadata:name: myapplication-hpaspec:scaleTargetRef:apiVersion: apps/v1kind: Deploymentname: myapplication-deploymentminReplicas: 3maxReplicas: 15metrics:- type: Podspods:metricName: myapplication_api_response_time_avgtargetAverageValue: "500"
Örnek
Şöyle yaparız. Burada kaynak olarak service kullanılıyor.
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: sample-metrics-app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: sample-metrics-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Object
object:
target:
kind: Service
name: sample-metrics-app
metricName: http_requests
targetValue: 100Şöyle yaparız
https://<apiserver_ip>/apis/custom-metrics.metrics.k8s.io/v1beta1\ /namespaces/default/services/sample-metrics-app/http_requests
Hiç yorum yok:
Yorum Gönder