Custom Metrics — application-specific metrics for HPA scaling.
1# Install Prometheus Adapter2apiVersion: apps/v13kind: Deployment4metadata:5 name: prometheus-adapter6 namespace: custom-metrics7spec:8 replicas: 19 template:10 spec:11 containers:12 - name: prometheus-adapter13 image: registry.k8s.io/prometheus-adapter/prometheus-adapter:v0.11.114 args:15 - --prometheus-url=http://prometheus:909016 - --metrics-relist-interval=30s17 - --config=/etc/adapter/config.yaml18 volumeMounts:19 - name: config20 mountPath: /etc/adapter21 volumes:22 - name: config23 configMap:24 name: prometheus-adapter-config25---26# HPA using custom metrics27apiVersion: autoscaling/v228kind: HorizontalPodAutoscaler29metadata:30 name: myapp-hpa31spec:32 scaleTargetRef:33 apiVersion: apps/v134 kind: Deployment35 name: myapp36 minReplicas: 237 maxReplicas: 2038 metrics:39 - type: Pods40 pods:41 metric:42 name: http_requests_per_second43 target:44 type: AverageValue45 averageValue: "1000"46 - type: Object47 object:48 describedObject:49 apiVersion: networking.k8s.io/v150 kind: Ingress51 name: myapp52 metric:53 name: requests_per_second54 target:55 type: Value56 value: "10k"57 - type: External58 external:59 metric:60 name: sqs_queue_length61 target:62 type: Value63 value: "30"
1# Commands2kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jq3kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/pods/*/http_requests_per_second" | jq45# Check HPA metrics6kubectl get hpa myapp-hpa -o yaml | grep -A 20 metrics7kubectl describe hpa myapp-hpa
Metric Types: