我试图使用python中的kubernetes-client在kubernetes中创建一个水平pod自动缩放器。为此,我使用了属于AutoscalingV2beta2Api的create_namespaced_horizontal_pod_autoscaler()函数
我的代码如下:
my_metrics = []
my_metrics.append(client.V2beta2MetricSpec(type='Pods', pods= client.V2beta2PodsMetricSource(metric=client.V2beta2MetricIdentifier(name='cpu'), target=client.V2beta2MetricTarget(average_utilization='50',type='Utilization'))))
body = client.V2beta2HorizontalPodAutoscaler(
api_version='autoscaling/v2beta2',
kind='HorizontalPodAutoscaler',
metadata=client.V1ObjectMeta(name='php-apache'),
spec= client.V2beta2HorizontalPodAutoscalerSpec(
max_replicas=10,
min_replicas=1,
metrics = my_metrics,
scale_target_ref = client.V2beta2CrossVersionObjectReference(kind='Object',name='php-apache')
))
v2 = client.AutoscalingV2beta2Api()
ret = v2.create_namespaced_horizontal_pod_autoscaler(namespace='default', body=body, pretty=True)
我得到的答复是:
HTTP response body: {
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "HorizontalPodAutoscaler in version \"v2beta2\" cannot be handled as a HorizontalPodAutoscaler: v2beta2.HorizontalPodAutoscaler.Spec: v2beta2.HorizontalPodAutoscalerSpec.Metrics: []v2beta2.MetricSpec: v2beta2.MetricSpec.Pods: v2beta2.PodsMetricSource.Target: v2beta2.MetricTarget.AverageUtilization: readUint32: unexpected character: \ufffd, error found in #10 byte of ...|zation\": \"50\", \"type|..., bigger context ...|\"name\": \"cpu\"}, \"target\": {\"averageUtilization\": \"50\", \"type\": \"Utilization\"}}, \"type\": \"Pods\"}], \"m|...",
"reason": "BadRequest",
"code": 400
}
我只想使用kubernetes客户端调用等效的:
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
任何可行的例子都是非常受欢迎的
上面的示例允许通过最新版本的k8s python client(v12.0.1)创建基于内存的hpa
以下错误:
意味着它需要
Uint32
,而您正在传递一个string
:将其更改为整数值,它应该可以工作
您可以在python client documentation中找到相同的信息(注意type列)
相关问题 更多 >
编程相关推荐