Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kubernetes 如何为类型:对象配置自动缩放_Kubernetes_Autoscaling - Fatal编程技术网

Kubernetes 如何为类型:对象配置自动缩放

Kubernetes 如何为类型:对象配置自动缩放,kubernetes,autoscaling,Kubernetes,Autoscaling,我配置了一个自定义指标 当我跑步时: kubectl get--raw”/api/custom.metrics.k8s.io/v1beta1/namespaces/my namespace/deployments.extensions/sample app/queue_length“| jq 我得到: ... "items": [ { "describedObject": { "kind": "Deployment", "namespace

我配置了一个自定义指标

当我跑步时:

kubectl get--raw”/api/custom.metrics.k8s.io/v1beta1/namespaces/my namespace/deployments.extensions/sample app/queue_length“| jq

我得到:

...
  "items": [
    {
      "describedObject": {
        "kind": "Deployment",
        "namespace": "my-namespace",
        "name": "sample-app",
        "apiVersion": "extensions/v1beta1"
      },
      "metricName": "queue_length",
      "timestamp": "2018-10-09T18:14:15Z",
      "value": "30"
    }
  ]
...
因此,我想用以下指标扩展部署:

kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
metadata:
  name: sample-app
  namespace: my-namespace
spec:
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: sample-app
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Object
    object:
      metricName: queue_length
      target:
        apiVersion: extensions/v1beta1
        kind: Deployment
        name: sample-app
      targetValue: 20
但它似乎不起作用,也许我必须指定
-type:Object
有些不同

我试图将
kind
更改为deployments、deployments.extension、deployments.extensions等,但不断出现错误
FailedGetScale

Upd.:我发现HPA对象和目标对象的名称空间应该是相同的,所以我更改了它。现在我越来越

the HPA was unable to compute the replica count: unable to get metric queue_length: Deployment on default sample-app/unable to fetch metrics from custom metrics API: the server could not find the metric queue_length for deployments.extensions sample-app
Upd2.:找到了答案:hpa在命名空间
default
中,而metric暴露在
我的命名空间
中。因此,应该小心使用名称空间

试试这个:

---
kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
metadata:
  name: sample-app
  namespace: my-namespace
spec:
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: sample-app
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Object
    object:
      target:
        kind: Service
        name: sample-app
      metricName: queue_length
      targetValue: 20

尝试但它也不起作用:
ScalingActive False FailedGetObjectMetric HPA无法计算副本计数:无法获取度量芹菜生产数据:默认示例应用程序上的服务/无法从自定义度量API获取度量:服务器找不到度量芹菜生产数据服务.扩展
。既然我有API路径
namespace/my namespace/deployments.extensions/sample app/queue_length
,那就应该有
deployment
了,我觉得糟糕。什么东西回来了?kubectl get--raw“/api/custom.metrics.k8s.io/v1beta1/namespace/my namespace/services/*/queue_length”| jq。