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 的自动扩展。
atomcodeClaude Code 的开源替代方案。连接任意大模型,编辑代码,运行命令,自动验证 — 全自动执行。用 Rust 构建,极致性能。 | An open-source alternative to Claude Code. Connect any LLM, edit code, run commands, and verify changes — autonomously. Built in Rust for speed. Get StartedRust0153- DDeepSeek-V4-ProDeepSeek-V4-Pro(总参数 1.6 万亿,激活 49B)面向复杂推理和高级编程任务,在代码竞赛、数学推理、Agent 工作流等场景表现优异,性能接近国际前沿闭源模型。Python00
LongCat-Video-Avatar-1.5最新开源LongCat-Video-Avatar 1.5 版本,这是一款经过升级的开源框架,专注于音频驱动人物视频生成的极致实证优化与生产级就绪能力。该版本在 LongCat-Video 基础模型之上构建,可生成高度稳定的商用级虚拟人视频,支持音频-文本转视频(AT2V)、音频-文本-图像转视频(ATI2V)以及视频续播等原生任务,并能无缝兼容单流与多流音频输入。00
auto-devAutoDev 是一个 AI 驱动的辅助编程插件。AutoDev 支持一键生成测试、代码、提交信息等,还能够与您的需求管理系统(例如Jira、Trello、Github Issue 等)直接对接。 在IDE 中,您只需简单点击,AutoDev 会根据您的需求自动为您生成代码。Kotlin03
Intern-S2-PreviewIntern-S2-Preview,这是一款高效的350亿参数科学多模态基础模型。除了常规的参数与数据规模扩展外,Intern-S2-Preview探索了任务扩展:通过提升科学任务的难度、多样性与覆盖范围,进一步释放模型能力。Python00
skillhubopenJiuwen 生态的 Skill 托管与分发开源方案,支持自建与可选 ClawHub 兼容。Python0112