次のkubernetesセットアップがあります
sn. type service namespace
1. statefulset rabbitmq rabbitmq
2. deployment pods default
3. hpa hpa default
メトリックは、次のように `/apis/custom.metrics.k8s.io/v1beta1 にエクスポートされます
{
"kind": "APIResourceList",
"apiVersion": "v1",
"groupVersion": "custom.metrics.k8s.io/v1beta1",
"resources": [
{
"name": "services/rabbitmq_queue_messages_ready",
"singularName": "",
"namespaced": true,
"kind": "MetricValueList",
"verbs": [
"get"
]
},
{
"name": "namespaces/rabbitmq_queue_messages_ready",
"singularName": "",
"namespaced": false,
"kind": "MetricValueList",
"verbs": [
"get"
]
},
{
"name": "pods/rabbitmq_queue_messages_ready",
"singularName": "",
"namespaced": true,
"kind": "MetricValueList",
"verbs": [
"get"
]
}
]
}
hpaの構成
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: demo-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: test-pod2
minReplicas: 1
maxReplicas: 2
metrics:
- type: Object
object:
metric:
name: "rabbitmq_queue_messages_ready"
describedObject:
apiVersion: custom.metrics.k8s.io/v1/beta1
kind: Service
name: rabbitmq
target:
type: Value
value: 50
default
名前空間にhpa をデプロイしようとすると、次のエラーが発生します。
ScalingActive False FailedGetObjectMetric the HPA was unable to compute the replica count: unable to get metric rabbitmq_queue_messages_ready: Service on default rabbitmq/unable to fetch metrics from custom metrics API: the server could not find the metric rabbitmq_queue_messages_ready for services rabbitmq
ただし、同じ hpa が設定されている場合は、hpa で名前空間rabbitmq
を実行します
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: demo-hpa
namespace: rabbitmq
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: test-pod2
minReplicas: 1
maxReplicas: 2
metrics:
- type: Object
object:
metric:
name: "rabbitmq_queue_messages_ready"
describedObject:
apiVersion: custom.metrics.k8s.io/v1/beta1
kind: Service
name: rabbitmq
target:
type: Value
value: 50
および deployment.yaml として
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-pod2
labels:
app: test-pod2
namespace: rabbimtq
spec:
replicas: 1
selector:
matchLabels:
app: test-pod2
template:
metadata:
labels:
app: test-pod2
spec:
containers:
- name: test-pod2
image: golang:1.16
command: ["sh", "-c", "tail -f /etc/hosts"]
展開は完璧に機能します。
サービス rabbitmq のメトリクスをrabbitmq
名前空間から他の名前空間にエクスポートして、スケーリングに使用できる方法はありますか???