教學課程:使用 Azure Kubernetes Service (AKS) 的 Azure Container Linux (ACL) 建立叢集

在本教學的 五部分中的第一部分中,你將學習如何:

  • 安裝 Kubernetes CLI:kubectl。
  • 建立 Azure 資源群組。
  • 建立並部署 ACL 叢集。
  • 設定 kubectl 連接你的 ACL 叢集。

在後續的教學中,你會學習如何將 ACL 節點池加入現有叢集,並將現有節點遷移到 ACL。

Azure Container Linux (ACL) 考慮事項與限制

在開始之前,請先回顧以下關於ACL的考量與限制:

先決條件

  • Azure Container Linux 需要 Azure CLI 版本 2.86.0 或更高版本。 使用指令 az version 來尋找版本。 若要升級至最新版本,請使用命令 az upgrade 。

設定環境變數

設定以下環境變數,為每個部署建立獨特的資源名稱:

export RESOURCE_GROUP="<your-resource-group-name>"
export REGION="<your-region>"
export CLUSTER_NAME="<your-cluster-name>"

建立資源群組

在 Azure 建立資源群組時,你必須指定一個位置。 這個位置是你資源群組元資料的儲存位置,也是如果你在建立資源時沒有指定其他區域,資源在 Azure 中會執行的位置。

使用 az group create 命令建立資源群組。

az group create --name $RESOURCE_GROUP --location $REGION

輸出範例:

{
  "id": "/subscriptions/xxxxx/resourceGroups/myACLResourceGroup",
  "location": "westus",
  "managedBy": null,
  "name": "myACLResourceGroup",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

建立 ACL 叢集

使用 az aks create 帶有 --os-sku AzureContainerLinux 參數的指令建立 AKS 叢集以配置 ACL 叢集。 以下範例建立一個包含三個節點的 ACL 叢集:

az aks create \
  --name $CLUSTER_NAME \
  --resource-group $RESOURCE_GROUP \
  --os-sku AzureContainerLinux \
  --node-count 3 \
  --generate-ssh-keys

輸出範例:

{
  "id": "/subscriptions/xxxxx/resourceGroups/myACLResourceGroup/providers/Microsoft.ContainerService/managedClusters/myACLCluster",
  "location": "westus",
  "name": "myACLCluster",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "type": "Microsoft.ContainerService/managedClusters"
}

幾分鐘後,命令會完成並傳回關於叢集的 JSON 格式資訊。

使用 kubectl 連線到叢集

設定 kubectl 使用 az aks get-credentials 命令連線到 Kubernetes 叢集。 以下範例取得 ACL 叢集的憑證:

az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME

確認與叢集的連線

使用命令 kubectl get nodes 驗證叢集的連線,以傳回叢集節點清單。

kubectl get nodes

輸出範例:

NAME                                STATUS   ROLES   AGE     VERSION
aks-nodepool1-00000000-0            Ready    agent   10m     v1.34.0
aks-nodepool1-00000000-1            Ready    agent   10m     v1.34.0
aks-nodepool1-00000000-2            Ready    agent   10m     v1.34.0

後續步驟

在這個教學中,你建立了並部署了一個 ACL 叢集。 在下一個教學中,你會學習如何將 ACL 節點池加入現有叢集。