練習 - 設定環境

已完成

注意

您需要能存取 Azure 訂用帳戶,才可在其中為此課程模組建立資源。

您使用 Azure Kubernetes Service (AKS) 叢集來裝載寵物店前端解決方案。 DevOps 小組會使用標準宣告式 YAML 檔案,以部署解決方案中的各種服務。 在目前的部署工作流程中,部署小組會為每個應用程式建立部署檔案。 小組正在檢閱 Helm 作為替代方案,以簡化雲端原生應用程式部署的管理。

在此練習中,您將設定環境以在整個課程模組中使用。 您將安裝和設定下列資源:

  • 複製包含範例應用程式的 GitHub 存放庫
  • 建立 Azure 資源群組以保存解決方案的資源
  • 建立 Azure Container Registry (ACR) 來儲存容器映像
  • 建立 Azure Kubernetes Service (AKS) 叢集來裝載應用程式
  • 使用 Azure CLI 連線至 AKS 叢集

設定環境

複製範例應用程式

  1. 瀏覽至 Azure Cloud Shell,並確定您使用的是 Bash 環境。

  2. 使用 az account set 命令設定您要用於本課程模組的訂用帳戶。

    az account set --subscription <subscription-name>
    
  3. 使用 git clone 命令將範例應用程式複製到您的開發環境。

    git clone https://github.com/Azure-Samples/aks-store-demo.git
    
  4. 使用 cd 變更為複製的目錄。

    cd aks-store-demo
    

建立 Azure 資源

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

    az group create --name <resource-group-name> --location <location>
    
  2. 使用 az acr create 命令建立 Azure 容器登錄,並提供您自己的唯一登錄名稱。 登錄名稱在 Azure 內必須是唯一的,且包含 5-50 個英數字元。

    az acr create --resource-group <resource-group-name> --name <acr-name> --sku Basic
    
  3. 使用 az aks create 命令建立 AKS 叢集,並使用 --attach-acr 參數將 ACR 附加至 AKS 叢集。

    az aks create --resource-group <resource-group-name> --name <aks-cluster-name> --node-count 2 --attach-acr <acr-name> --generate-ssh-keys
    
  4. 使用 az aks get-credentials 命令連線至您的 AKS 叢集。

    az aks get-credentials --resource-group <resource-group-name> --name <aks-cluster-name>
    
  5. 使用 kubectl get nodes 命令確認 AKS 叢集的連線。

    kubectl get nodes