第3步:一步步设置 AKS

发布: (2025年12月27日 GMT+8 08:01)
2 min read
原文: Dev.to

Source: Dev.to

前置条件

az version
az login

步骤 1:创建 AKS 集群

az aks create \
  --resource-group devops-rg \
  --name myAKSCluster \
  --node-count 2 \
  --enable-addons monitoring \
  --generate-ssh-keys

步骤 2:将 AKS 连接到 ACR

az aks update \
  --resource-group devops-rg \
  --name myAKSCluster \
  --attach-acr 

步骤 3:获取用于 kubectl 的 AKS 凭证

az aks get-credentials \
  --resource-group devops-rg \
  --name myAKSCluster

步骤 4:验证连接

kubectl get nodes

步骤 5:验证命名空间

kubectl get namespaces

步骤 6(可选):启用自动伸缩

az aks update \
  --resource-group devops-rg \
  --name myAKSCluster \
  --enable-cluster-autoscaler \
  --min-count 1 \
  --max-count 5

步骤 7:创建部署

kubectl create deployment myapp --image=myapp

步骤 8:更新并重启部署镜像

编辑部署以使用你的 ACR 登录服务器镜像,例如:

# 在部署规范中设置:
image: .azurecr.io/myapp:latest

然后重启部署:

kubectl rollout restart deployment myapp

检查 Pod:

kubectl get pods

步骤 9:暴露部署

kubectl expose deployment myapp \
  --port=80 \
  --target-port=3000 \
  --type=LoadBalancer

步骤 10:获取服务

kubectl get service myapp

步骤 11:在浏览器中测试

打开网页浏览器,访问 myapp 服务的外部 IP 地址。

Back to Blog

相关文章

阅读更多 »

StatefulSet 项目

先决条件:StatefulSet 需要以下组件: - Headless Service —— 为每个 pod 提供稳定的 DNS。 - StatefulSet manifest —— 定义 pod……