关于 aks-automatic-2025
面向 Azure Kubernetes Service 用户的 AKS Automatic 知识指南,介绍集群自动化、扩缩容、安全、网络与成本配置,并提供命令和示例清单。
主要功能
- 01托管控制平面与节点维护
- 02Karpenter 节点动态配置
- 03HPA、VPA 与 KEDA 扩缩容
- 04身份验证与网络安全配置
- 05监控及成本优化指南
适用场景
- 01创建和配置 AKS Automatic 集群
- 02为工作负载设置自动扩缩容
- 03排查节点配置与身份问题
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ josiahsiegel/ claude-plugin-marketplace --skill aks-automatic-2025安装后在 Claude Code 中输入/aks-automatic-2025确认已加载。
详细介绍
AKS Automatic - 2025 年 GA 功能
Azure Kubernetes Service Automatic 模式的完整知识库(2025 年 10 月正式发布)。
概述
AKS Automatic 是一项完全托管的 Kubernetes 服务,通过智能自动化和内置最佳实践消除运维负担。
主要功能(2025 年 10 月正式发布)
1. 零运维负担
- 完全托管的控制平面和工作节点
- 自动进行 OS 修补和安全更新
- 内置监控和诊断
- 集成安全与合规功能
2. Karpenter 集成
- 根据实时需求动态预配节点
- 通过智能装箱优化成本
- 自动整合和取消预配节点
- 支持多个节点池和实例类型
3. 自动扩缩(默认启用)
- Horizontal Pod Autoscaler(HPA):根据 CPU/内存扩缩 Pod
- Vertical Pod Autoscaler(VPA):调整 Pod 资源请求/限制
- KEDA:针对外部触发器的事件驱动自动扩缩
4. 增强安全性
- 集成 Microsoft Entra ID 进行身份验证
- 使用 Azure RBAC 进行 Kubernetes 授权
- 默认启用网络策略
- 自动应用安全补丁
- 使用工作负载标识进行 Pod 级身份验证
5. 高级网络
- 使用 Azure CNI Overlay 高效利用 IP
- 使用 Cilium 数据平面实现高性能网络
- 使用网络策略进行微分段
- 支持专用集群
6. 新计费模式(2025 年 10 月 19 日起生效)
- 托管控制平面费用:$0.16/集群/小时
- 根据实际节点用量收取计算费用
- 不单独收取集群管理费用
- 通过 Karpenter 优化节省成本
7. 节点操作系统
- Kubernetes < 1.34 使用 Ubuntu 22.04
- Kubernetes >= 1.34 使用 Ubuntu 24.04
- 使用节点映像通道自动升级 OS
创建 AKS Automatic 集群
基本创建
az aks create \
--resource-group MyRG \
--name MyAKSAutomatic \
--sku automatic \
--kubernetes-version 1.34 \
--location eastus
适用于生产环境的配置
az aks create \
--resource-group MyRG \
--name MyAKSAutomatic \
--location eastus \
--sku automatic \
--tier standard \
\
# Kubernetes version
--kubernetes-version 1.34 \
\
# Karpenter (default in automatic mode)
--enable-karpenter \
\
# Networking
--network-plugin azure \
--network-plugin-mode overlay \
--network-dataplane cilium \
--service-cidr 10.0.0.0/16 \
--dns-service-ip 10.0.0.10 \
--load-balancer-sku standard \
\
# Use custom VNet (optional)
--vnet-subnet-id /subscriptions/<sub-id>/resourceGroups/MyRG/providers/Microsoft.Network/virtualNetworks/MyVNet/subnets/AKSSubnet \
\
# Availability zones
--zones 1 2 3 \
\
# Authentication and authorization
--enable-managed-identity \
--enable-aad \
--enable-azure-rbac \
--aad-admin-group-object-ids <group-object-id> \
\
# Auto-upgrade
--auto-upgrade-channel stable \
--node-os-upgrade-channel NodeImage \
\
# Security
--enable-defender \
--enable-workload-identity \
--enable-oidc-issuer \
\
# Monitoring
--enable-addons monitoring \
--workspace-resource-id /subscriptions/<sub-id>/resourceGroups/MyRG/providers/Microsoft.OperationalInsights/workspaces/MyWorkspace \
\
# Tags
--tags Environment=Production ManagedBy=AKSAutomatic
使用 Azure Policy 附加组件
az aks create \
--resource-group MyRG \
--name MyAKSAutomatic \
--sku automatic \
--enable-addons azure-policy \
--kubernetes-version 1.34
Karpenter 配置
AKS Automatic 使用 Karpenter 智能预配节点。使用 AKSNodeClass 和 NodePool CRD 自定义节点预配。
默认 AKSNodeClass
apiVersion: karpenter.azure.com/v1alpha1
kind: AKSNodeClass
metadata:
name: default
spec:
# OS Image - Ubuntu 24.04 for K8s 1.34+
osImage:
sku: Ubuntu
version: "24.04"
# VM Series
vmSeries:
- Standard_D
- Standard_E
# Max pods per node
maxPodsPerNode: 110
# Security
securityProfile:
sshAccess: Disabled
securityType: Standard
自定义 NodePool
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
name: general-purpose
spec:
# Constraints
template:
spec:
requirements:
- key: kubernetes.io/arch
operator: In
values: ["amd64"]
- key: karpenter.sh/capacity-type
operator: In
values: ["on-demand"]
- key: kubernetes.azure.com/agentpool
operator: In
values: ["general"]
# Node labels
labels:
workload-type: general
# Taints (optional)
taints:
- key: "dedicated"
value: "general"
effect: "NoSchedule"
# NodeClass reference
nodeClassRef:
group: karpenter.azure.com
kind: AKSNodeClass
name: default
# Limits
limits:
cpu: "1000"
memory: 4000Gi
# Disruption budget
disruption:
consolidationPolicy: WhenEmpty
consolidateAfter: 30s
expireAfter: 720h # 30 days
budgets:
- nodes: "10%"
duration: 5m
用于 AI 工作负载的 GPU NodePool
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
name: gpu-workloads
spec:
template:
spec:
requirements:
- key: kubernetes.io/arch
operator: In
values: ["amd64"]
- key: karpenter.sh/capacity-type
operator: In
values: ["on-demand"]
- key: node.kubernetes.io/instance-type
operator: In
values: ["Standard_NC6s_v3", "Standard_NC12s_v3", "Standard_NC24s_v3"]
labels:
workload-type: gpu
gpu-type: nvidia-v100
taints:
- key: "nvidia.com/gpu"
value: "true"
effect: "NoSchedule"
nodeClassRef:
group: karpenter.azure.com
kind: AKSNodeClass
name: gpu-nodeclass
limits:
cpu: "200"
memory: 800Gi
nvidia.com/gpu: "16"
disruption:
consolidationPolicy: WhenEmpty
consolidateAfter: 300s
使用 HPA、VPA 和 KEDA 进行自动扩缩
Horizontal Pod Autoscaler(HPA)
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
minReplicas: 2
maxReplicas: 50
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
behavior:
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 100
periodSeconds: 15
- type: Pods
value: 4
periodSeconds: 15
selectPolicy: Max
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 50
periodSeconds: 15
Vertical Pod Autoscaler(VPA)
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: myapp-vpa
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
updatePolicy:
updateMode: "Auto" # Auto, Recreate, Initial, Off
resourcePolicy:
containerPolicies:
- containerName: "*"
minAllowed:
cpu: 100m
memory: 128Mi
maxAllowed:
cpu: 4
memory: 8Gi
controlledResources: ["cpu", "memory"]
controlledValues: RequestsAndLimits
KEDA ScaledObject(事件驱动)
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: myapp-queue-scaler
spec:
scaleTargetRef:
name: myapp
minReplicaCount: 0 # Scale to zero
maxReplicaCount: 100
pollingInterval: 30
cooldownPeriod: 300
triggers:
# Azure Service Bus Queue
- type: azure-servicebus
metadata:
queueName: myqueue
namespace: myservicebus
messageCount: "5"
authenticationRef:
name: azure-servicebus-auth
# Azure Storage Queue
- type: azure-queue
metadata:
queueName: myqueue
queueLength: "10"
accountName: mystorageaccount
authenticationRef:
name: azure-storage-auth
# Prometheus metrics
- type: prometheus
metadata:
serverAddress: http://prometheus.monitoring.svc.cluster.local:9090
metricName: http_requests_per_second
threshold: "100"
query: sum(rate(http_requests_total[2m]))
工作负载标识(取代 AAD Pod Identity)
设置
# Workload identity is enabled by default in AKS Automatic
# Create managed identity
az identity create \
--name myapp-identity \
--resource-group MyRG
# Get identity details
export IDENTITY_CLIENT_ID=$(az identity show -g MyRG -n myapp-identity --query clientId -o tsv)
export IDENTITY_OBJECT_ID=$(az identity show -g MyRG -n myapp-identity --query principalId -o tsv)
# Assign role to identity
az role assignment create \
--assignee $IDENTITY_OBJECT_ID \
--role "Storage Blob Data Contributor" \
--scope /subscriptions/<sub-id>/resourceGroups/MyRG/providers/Microsoft.Storage/storageAccounts/mystorage
# Create federated credential
export AKS_OIDC_ISSUER=$(az aks show -g MyRG -n MyAKSAutomatic --query oidcIssuerProfile.issuerUrl -o tsv)
az identity federated-credential create \
--name myapp-federated-credential \
--identity-name myapp-identity \
--resource-group MyRG \
--issuer $AKS_OIDC_ISSUER \
--subject system:serviceaccount:default:myapp-sa
Kubernetes 资源
# Service Account
apiVersion: v1
kind: ServiceAccount
metadata:
name: myapp-sa
namespace: default
annotations:
azure.workload.identity/client-id: "<IDENTITY_CLIENT_ID>"
---
# Deployment using workload identity
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 2
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
azure.workload.identity/use: "true" # Enable workload identity
spec:
serviceAccountName: myapp-sa
containers:
- name: myapp
image: myregistry.azurecr.io/myapp:latest
env:
- name: AZURE_CLIENT_ID
value: "<IDENTITY_CLIENT_ID>"
- name: AZURE_TENANT_ID
value: "<TENANT_ID>"
- name: AZURE_FEDERATED_TOKEN_FILE
value: /var/run/secrets/azure/tokens/azure-identity-token
volumeMounts:
- name: azure-identity-token
mountPath: /var/run/secrets/azure/tokens
readOnly: true
volumes:
- name: azure-identity-token
projected:
sources:
- serviceAccountToken:
path: azure-identity-token
expirationSeconds: 3600
audience: api://AzureADTokenExchange
监控与可观测性
启用 Container Insights
# Already enabled with --enable-addons monitoring
# Query logs using Azure Monitor
# Get cluster logs
az monitor log-analytics query \
--workspace <workspace-id> \
--analytics-query "KubePodInventory | where ClusterName == 'MyAKSAutomatic' | take 10" \
--output table
# Get Karpenter logs
kubectl logs -n kube-system -l app.kubernetes.io/name=karpenter
Prometheus 和 Grafana
# Enable managed Prometheus
az aks update \
--resource-group MyRG \
--name MyAKSAutomatic \
--enable-azure-monitor-metrics
# Access Grafana dashboards through Azure Portal
成本优化
计费模式(2025 年 10 月)
- 控制平面:每个集群每小时 $0.16
- 计算:按实际节点用量付费
- Karpenter:自动装箱和整合
- 缩减至零:可通过 KEDA 和 Karpenter 实现
节省成本的建议
- 对非关键工作负载使用 Spot 实例
- key: karpenter.sh/capacity-type
operator: In
values: ["spot"]
- 配置积极的整合策略
disruption:
consolidationPolicy: WhenUnderutilized
consolidateAfter: 30s
- 实施 Pod 中断预算
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: myapp-pdb
spec:
minAvailable: 1
selector:
matchLabels:
app: myapp
- 使用 VPA 调整资源规格
- VPA 根据实际用量自动调整资源请求
从标准 AKS 迁移到 Automatic
AKS Automatic 是一种新的集群模式,不支持就地迁移。请按以下步骤操作:
- 创建新的 AKS Automatic 集群
- 在新集群中安装工作负载
- 验证功能
- 切换流量(DNS、负载均衡器)
- 停用旧集群
最佳实践
✓ 为新的生产集群使用 AKS Automatic ✓ 启用工作负载身份进行 Pod 身份验证 ✓ 为特定工作负载类型配置自定义 NodePools ✓ 实施 HPA、VPA 和 KEDA,实现全面扩缩 ✓ 为批处理和容错工作负载使用 Spot 实例 ✓ 启用 Container Insights 和 Managed Prometheus ✓ 为关键应用配置 Pod 中断预算 ✓ 使用网络策略进行微隔离 ✓ 启用 Azure Policy 附加组件以满足合规要求 ✓ 使用 Flux 或 Argo CD 实施 GitOps
故障排除
检查 Karpenter 状态
kubectl logs -n kube-system -l app.kubernetes.io/name=karpenter --tail=100
kubectl get nodepools
kubectl get nodeclaims
查看节点预配事件
kubectl get events --field-selector involvedObject.kind=NodePool -A
调试工作负载身份问题
# Check service account annotation
kubectl get sa myapp-sa -o yaml
# Check pod labels
kubectl get pod <pod-name> -o yaml | grep azure.workload.identity
# Check federated credential
az identity federated-credential show \
--identity-name myapp-identity \
--resource-group MyRG \
--name myapp-federated-credential
参考资料
AKS Automatic 代表着 Azure 托管 Kubernetes 的未来——无需运维开销,实现最大程度的自动化!
评论
支持 Markdown