我有一个 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 时,请rabbitmq
使用 hpa进行命名空间
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
命名空间导出到任何其他命名空间,然后我可以将其用于扩展???