Azure Kubernetes Metrics Adapter 使用教程
1. 项目介绍
Azure Kubernetes Metrics Adapter 是一个用于 Azure 服务的 Kubernetes 自定义指标 API 和外部指标 API 的实现。该适配器允许你使用 Azure 资源(如 Service Bus 队列)和存储在 Application Insights 中的自定义指标,通过 Kubernetes 的水平 Pod 自动扩展器(HPA)来扩展应用程序部署的 Pod。
主要功能
- 自定义指标 API:支持从 Application Insights 获取自定义指标。
- 外部指标 API:支持从 Azure 资源(如 Service Bus 队列)获取外部指标。
- 水平 Pod 自动扩展:通过 HPA 根据获取的指标自动扩展 Pod。
2. 项目快速启动
2.1 环境准备
确保你已经安装了以下工具:
- Kubernetes 集群
- Helm
- Azure CLI
2.2 安装步骤
2.2.1 克隆项目仓库
git clone https://github.com/Azure/azure-k8s-metrics-adapter.git
cd azure-k8s-metrics-adapter
2.2.2 创建命名空间
kubectl create namespace custom-metrics
2.2.3 安装 Helm Chart
helm install --name my-release charts/azure-k8s-metrics-adapter --namespace custom-metrics
2.2.4 创建服务主体和密钥
az ad sp create-for-rbac -n "azure-k8s-metric-adapter-sp" --role "Monitoring Reader" --scopes /subscriptions/[SubID]/resourceGroups/[ResourceGroup1]
使用创建的服务主体信息创建 Kubernetes 密钥:
kubectl create secret generic azure-k8s-metrics-adapter -n custom-metrics \
--from-literal=azure-tenant-id=<tenantid> \
--from-literal=azure-client-id=<clientid> \
--from-literal=azure-client-secret=<secret>
2.2.5 部署适配器
kubectl apply -f https://raw.githubusercontent.com/Azure/azure-k8s-metrics-adapter/master/deploy/adapter.yaml
2.2.6 部署指标配置
kubectl apply -f https://raw.githubusercontent.com/Azure/azure-k8s-metrics-adapter/master/samples/resources/externalmetric-example.yaml
2.2.7 部署 HPA
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: consumer-scaler
spec:
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: consumer
minReplicas: 1
maxReplicas: 10
metrics:
- type: External
external:
metricName: queuemessages
targetValue: 30
3. 应用案例和最佳实践
3.1 使用 Service Bus 队列进行自动扩展
通过 Azure Service Bus 队列的消息数量来触发 Pod 的自动扩展。配置 HPA 时,指定 queuemessages
作为外部指标,并设置目标值。
3.2 使用 Application Insights 进行自动扩展
通过 Application Insights 中的自定义指标(如每秒请求数)来触发 Pod 的自动扩展。配置 HPA 时,指定自定义指标名称,并设置目标值。
4. 典型生态项目
4.1 Azure Kubernetes Service (AKS)
Azure Kubernetes Metrics Adapter 主要用于 AKS 集群中,通过 Azure 资源和自定义指标来实现 Pod 的自动扩展。
4.2 Application Insights
Application Insights 用于收集和分析应用程序的性能指标,Azure Kubernetes Metrics Adapter 可以从 Application Insights 中获取自定义指标,用于自动扩展。
4.3 Azure Monitor
Azure Monitor 提供对 Azure 资源的监控和警报功能,Azure Kubernetes Metrics Adapter 可以从 Azure Monitor 中获取外部指标,用于自动扩展。
通过以上步骤和案例,你可以快速上手并使用 Azure Kubernetes Metrics Adapter 来实现 Kubernetes 集群中 Pod 的自动扩展。
- QQwen3-Next-80B-A3B-InstructQwen3-Next-80B-A3B-Instruct 是一款支持超长上下文(最高 256K tokens)、具备高效推理与卓越性能的指令微调大模型00
- QQwen3-Next-80B-A3B-ThinkingQwen3-Next-80B-A3B-Thinking 在复杂推理和强化学习任务中超越 30B–32B 同类模型,并在多项基准测试中优于 Gemini-2.5-Flash-Thinking00
GitCode-文心大模型-智源研究院AI应用开发大赛
GitCode&文心大模型&智源研究院强强联合,发起的AI应用开发大赛;总奖池8W,单人最高可得价值3W奖励。快来参加吧~0265cinatra
c++20实现的跨平台、header only、跨平台的高性能http库。C++00AI内容魔方
AI内容专区,汇集全球AI开源项目,集结模块、可组合的内容,致力于分享、交流。02- HHunyuan-MT-7B腾讯混元翻译模型主要支持33种语言间的互译,包括中国五种少数民族语言。00
GOT-OCR-2.0-hf
阶跃星辰StepFun推出的GOT-OCR-2.0-hf是一款强大的多语言OCR开源模型,支持从普通文档到复杂场景的文字识别。它能精准处理表格、图表、数学公式、几何图形甚至乐谱等特殊内容,输出结果可通过第三方工具渲染成多种格式。模型支持1024×1024高分辨率输入,具备多页批量处理、动态分块识别和交互式区域选择等创新功能,用户可通过坐标或颜色指定识别区域。基于Apache 2.0协议开源,提供Hugging Face演示和完整代码,适用于学术研究到工业应用的广泛场景,为OCR领域带来突破性解决方案。00- HHowToCook程序员在家做饭方法指南。Programmer's guide about how to cook at home (Chinese only).Dockerfile06
- PpathwayPathway is an open framework for high-throughput and low-latency real-time data processing.Python00
热门内容推荐
最新内容推荐
项目优选









