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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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 AWS Cloudwatch适配器未获取EKS HPA自动缩放的自定义度量值_Kubernetes_Amazon Cloudwatch_Autoscaling_Amazon Eks_Hpa - Fatal编程技术网

Kubernetes AWS Cloudwatch适配器未获取EKS HPA自动缩放的自定义度量值

Kubernetes AWS Cloudwatch适配器未获取EKS HPA自动缩放的自定义度量值,kubernetes,amazon-cloudwatch,autoscaling,amazon-eks,hpa,Kubernetes,Amazon Cloudwatch,Autoscaling,Amazon Eks,Hpa,我正试图通过Kubernetes Cloudwatch适配器启用基于自定义Cloudwatch度量的AWS EKS自动缩放。我已将自定义指标推送到AWS Cloudwatch,并验证了它们出现在Cloudwatch控制台中,并且可以使用boto3客户端get_metric_数据检索。这是我用来将自定义度量发布到Cloudwatch的代码: import boto3 from datetime import datetime client = boto3.client('cloudwatch')

我正试图通过Kubernetes Cloudwatch适配器启用基于自定义Cloudwatch度量的AWS EKS自动缩放。我已将自定义指标推送到AWS Cloudwatch,并验证了它们出现在Cloudwatch控制台中,并且可以使用boto3客户端get_metric_数据检索。这是我用来将自定义度量发布到Cloudwatch的代码:

import boto3
from datetime import datetime

client = boto3.client('cloudwatch')

cloudwatch_response = client.put_metric_data(
    Namespace='TestMetricNS',
    MetricData=[
        {
            'MetricName': 'TotalUnprocessed',
            'Timestamp': datetime.now(),
            'Value': 40,
            'Unit': 'Megabytes',
        }
    ]
)
我有以下yaml文件,用于在kubernetes中建立外部度量和hpa autoscaler:

extMetricCustom.yaml:

apiVersion: metrics.aws/v1alpha1
kind: ExternalMetric
metadata:
  name: test-custom-metric
spec:
  name: test-custom-metric
  resource:
    resource: "deployment"
  queries:
    - id: sqs_test
      metricStat:
        metric:
          namespace: "TestMetricNS"
          metricName: "TotalUnprocessed"
        period: 60
        stat: Average
        unit: Megabytes
      returnData: true
hpaCustomMetric.yaml

kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
metadata:
  name: test-scaler
spec:
  scaleTargetRef:
    apiVersion: apps/v1beta1
    kind: Deployment
    name: sqs-consumer
  minReplicas: 1
  maxReplicas: 4
  metrics:
  - type: External
    external:
      metricName: test-custom-metric
      targetAverageValue: 2
当我评估Kubernetes Cloudwatch适配器是否正确获取我的自定义指标(kubectl get hpa)时,它总是显示该指标为0:

NAME          REFERENCE                 TARGETS     MINPODS   MAXPODS   REPLICAS   AGE
test-scaler   Deployment/sqs-consumer   0/2 (avg)   1         4         1          161m

如何根据我的Cloudwatch自定义指标正确地进行自动缩放?

与OP合作解决了这一带外问题,并在当天晚些时候为这个问题打开了选项卡,因此,如果有人偶然发现,请将结果发布在此处供后人参考

问题的根本原因是时区冲突。度量监视器基于“当前”度量,但度量生成器脚本的下一行生成的时间戳没有指定时区,也在本地时区中

“时间戳”:datetime.now(),
由于当前时区“无数据”(由于-X UTC偏移量,过去只有X小时的数据),系统没有启动缩放,因为有效地存在值“0”/nil/null。相反,可以指定UTC时间字符串以确保生成的度量是及时的:

“时间戳”:datetime.utcnow(),
第二个考虑因素是Kubernetes节点需要访问CloudWatch来轮询度量。这是通过附加到节点的IAM角色来完成的:

{
“版本”:“2012-10-17”,
“声明”:[
{
“效果”:“允许”,
“行动”:[
“cloudwatch:GetMetricData”
],
“资源”:“*”
}
]
}