Share via


クイック スタート: Azure Resource Manager テンプレートを使用して Kubernetes クラスターをデプロイする

適用対象: Azure Stack HCI バージョン 23H2

このクイックスタートでは、Azure Resource Manager テンプレートを使用して AKS Arc に Kubernetes クラスターをデプロイする方法について説明します。 Azure Arc は、Azure 管理機能を任意の場所の Kubernetes クラスターに拡張し、さまざまな環境を管理するための統一されたアプローチを提供します。

開始する前に

この記事では、Kubernetes の基本的な概念を理解していることを前提としています。

Resource Manager テンプレートをデプロイするには、デプロイするリソースに対する書き込みアクセス権と、Microsoft.Resources/deployments リソースの種類に対するすべての操作へのアクセス権が必要です。 たとえば、仮想マシンをデプロイするには、 Microsoft.Compute/virtualMachines/write および Microsoft.Resources/deployments/* アクセス許可が必要です。 ロールとアクセス許可の一覧については、Azure の組み込みロールに関するページを参照してください。

前提条件

  • アクティブなサブスクリプションが含まれる Azure アカウント。
  • Azure Stack HCI 23H2 クラスター。
  • 最新の Azure CLI バージョン。

手順 1: Azure アカウントを準備する

  1. Azure にサインインする: ターミナルまたはコマンド プロンプトを開き、Azure CLI を使用して Azure アカウントにサインインします。

    az login
    
  2. サブスクリプションを設定する: をサブスクリプション ID に置き換えます <your-subscription-id>

    az account set --subscription "<your-subscription-id>"
    

手順 2: Azure CLI を使用して SSH キー ペアを作成する

az sshkey create --name "mySSHKey" --resource-group "myResourceGroup"

または、 ssh-keygen を使用して SSH キー ペアを作成します。

ssh-keygen -t rsa -b 4096

テンプレートをデプロイするには、SSH ペアから公開キーを指定する必要があります。 公開キーを取得するには、 コマンドを az sshkey show 使用します。

az sshkey show --name "mySSHKey" --resource-group "myResourceGroup" --query "publicKey"

既定では、SSH キー ファイルは ~/.ssh ディレクトリに作成されます。 または ssh-keygen コマンドをaz sshkey create実行して、既存の SSH キー ペアを同じ名前で上書きします。

SSH キーの作成の詳細については、Azure での認証用の SSH キーの作成と管理に関するページを参照してください。

手順 3: テンプレートを確認する

このクイックスタートで使用するテンプレートは、Azure クイックスタート テンプレート リポジトリから取得しています。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "provisionedClusterName": {
          "type": "string",
          "defaultValue": "aksarc-armcluster",
          "metadata": {
              "description": "The name of the AKS Arc Cluster resource."
          }
      },
      "location": {
          "type": "string",
          "defaultValue": "eastus",
          "metadata": {
              "description": "The location of the AKS Arc Cluster resource."
          }
      },
      "resourceTags": {
            "type": "object",
            "defaultValue": {}
        },
      "sshRSAPublicKey": {
          "type": "string",
          "metadata": {
              "description": "Configure all linux machines with the SSH RSA public key string. Your key should include three parts, for example 'ssh-rsa AAAAB...snip...UcyupgH '"
          }
      },
       "enableAHUB": {
            "type": "string",
            "defaultValue": "NotApplicable",
            "metadata": {
                "description": "Azure Hybrid Benefit for Windows Server licenses. NotApplicable, True, False."
            }
        },
       "agentName": {
              "type": "string",
              "defaultValue": "nodepool",
              "metadata": {
                  "description": "The name of the node pool."
              }
          },
        "agentVMSize": {
            "type": "string",
            "defaultValue": "Standard_A4_v2",
            "metadata": {
                  "description": "The VM size for node pools."
            }
        },
        "agentCount": {
              "type": "int",
              "defaultValue": 1,
              "minValue": 1,
              "maxValue": 50,
              "metadata": {
                  "description": "The number of nodes for the cluster."
              }
          },
          "agentOsType": {
              "type": "string",
              "defaultValue": "Linux",
              "metadata": {
                  "description": "The OS Type for the agent pool. Values are Linux and Windows."
              }
          },
         "loadBalancerCount": {
            "type": "int",
            "defaultValue": 0,
            "metadata": {
                "description": "The number of load balancers."
            }
        },
          "kubernetesVersion": {
              "type": "string",
              "metadata": {
                  "description": "The version of Kubernetes."
              }
          },
          "controlPlaneNodeCount": {
              "type": "int",
              "defaultValue": 1,
              "minValue": 1,
              "maxValue": 5,
              "metadata": {
                  "description": "The number of control plane nodes for the cluster."
              }
          },
          "controlPlaneIp": {
            "type": "string",
            "defaultValue": "<default_value>",
              "metadata": {
                  "description": "Control plane IP address."
              }
         },
          "controlPlaneVMSize": {
              "type": "string",
              "defaultValue": "Standard_A4_v2",
              "metadata": {
                  "description": "The VM size for control plane."
              }
          },
          "vnetSubnetIds": {
              "type": "array",
              "metadata": {
                  "description": "List of subnet Ids for the AKS cluster."
              }
          },
          "podCidr": {
            "type": "string",
            "defaultValue": "10.244.0.0/16",
            "metadata": {
                  "description": "The VM size for control plane."
              }
          },
          "networkPolicy": {
            "type": "string",
            "defaultValue": "calico",
            "metadata": {
                  "description": "Network policy to use for Kubernetes pods. Only options supported is calico."
              }
          },
          "customLocation": {
            "type": "string",
            "metadata": {
                  "description": "Fully qualified custom location resource Id."
              }
          }
      },
      "resources": [
      {
          "apiVersion": "2024-01-01",
          "type": "Microsoft.Kubernetes/ConnectedClusters",
          "kind": "ProvisionedCluster",
          "location": "[parameters('location')]",
          "name": "[parameters('provisionedClusterName')]",
          "tags": "[parameters('resourceTags')]",
          "identity": {
              "type": "SystemAssigned"
          },
          "properties": {
              "agentPublicKeyCertificate":"" ,
              "aadProfile": {
                  "enableAzureRBAC": false
              }
          }
      },
      {
          "apiVersion": "2024-01-01",
          "type": "microsoft.hybridcontainerservice/provisionedclusterinstances",
          "name": "default",
          "scope": "[concat('Microsoft.Kubernetes/ConnectedClusters', '/', parameters('provisionedClusterName'))]",
          "dependsOn": [
              "[resourceId('Microsoft.Kubernetes/ConnectedClusters', parameters('provisionedClusterName'))]"
          ],
          "properties": {
          "agentPoolProfiles": [
            {
              "count": "[parameters('agentCount')]",
              "name":"[parameters('agentName')]",
              "osType": "[parameters('agentOsType')]",
              "vmSize": "[parameters('agentVMSize')]"
            }
          ],
          "cloudProviderProfile": {
            "infraNetworkProfile": {
                  "vnetSubnetIds": "[parameters('vnetSubnetIds')]"
            }
          },
          "controlPlane": {
            "count": "[parameters('controlPlaneNodeCount')]",
            "controlPlaneEndpoint": {
                        "hostIP": "[parameters('controlPlaneIp')]"
                    },
            "vmSize": "[parameters('controlPlaneVMSize')]"
          },
         "licenseProfile": {
            "azureHybridBenefit": "[parameters('enableAHUB')]"
         },
          "kubernetesVersion": "[parameters('kubernetesVersion')]",
          "linuxProfile": {
            "ssh": {
              "publicKeys": [
                {
                  "keyData": "[parameters('sshRSAPublicKey')]"
                }
              ]
            }
          },
        "networkProfile": {
          "loadBalancerProfile": {
            "count": "[parameters('loadBalancerCount')]"
          },
          "networkPolicy": "[parameters('networkPolicy')]",
          "podCidr": "[parameters('podCidr')]"
        },
        "storageProfile": {
          "nfsCsiDriver": {
            "enabled": false
          },
          "smbCsiDriver": {
            "enabled": false
          }
        }
        },
        "extendedLocation": {
            "name": "[parameters('customLocation')]",
            "type": "CustomLocation"
        }
      }
    ]
  }

手順 4: テンプレートのデプロイ

テンプレートをデプロイするには、次のコマンドを実行して Kubernetes クラスターをデプロイします。

az deployment group create \
--name "<deployment-name>" \
--resource-group "<resource-group-name>" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.kubernetes/aks-arc/azuredeploy.json" \
--parameters provisionedClusterName="<cluster-name> location="eastus" sshRSApublicKey="" etc..."

クラスターの作成には数分かかります。 クラスターが正常にデプロイされるのを待ってから、次の手順に進みます。

手順 5: デプロイを確認する

デプロイが完了したら、次のコマンドを使用して、Kubernetes クラスターが稼働していることを確認します。

az aksarc show --resource-group "<resource-group-name>" --name "<cluster-name>" --output table

手順 6: クラスターに接続する

  1. クラスターに接続するには、 コマンドを az connectedk8s proxy 実行します。 コマンドは、クライアント コンピューターでプロキシ バイナリをダウンロードして実行し、クラスターに関連付けられている kubeconfig ファイルをフェッチします。

    az connectedk8s proxy --name <cluster name> -g <resource group>
    

    または、Kubernetes コマンド ライン クライアント kubectl を使用します。 Azure Cloud Shellを使用する場合、kubectl は既にインストールされています。 kubectl をローカルにインストールして実行するには、 コマンドをaz aksarc install-cli実行します。

    コマンドを使用して Kubernetes クラスターに接続するように kubectlaz aksarc get-credentials 構成します。 このコマンドは、資格情報をダウンロードし、それを使用するように Kubernetes CLI を構成します。

    az aksarc get-credentials --resource-group "<resource-group-name>" --name "<cluster-name>"
    
  2. kubectl get コマンドを使用して、ご利用のクラスターへの接続を確認します。 このコマンドは、クラスター ノードの一覧を返します。

    kubectl get nodes -A --kubeconfig .\<path to kubecofig> 
    

    次の出力例は、前の手順で作成した 3 つのノードを示しています。 ノードの状態が "準備完了" であることを確認します。

    NAME                                STATUS   ROLES   AGE   VERSION
    aks-agentpool-27442051-vmss000000   Ready    agent   10m   v1.27.7
    aks-agentpool-27442051-vmss000001   Ready    agent   10m   v1.27.7
    aks-agentpool-27442051-vmss000002   Ready    agent   11m   v1.27.7
    

Template resources

connectedClusters

名前 説明
type リソースの種類。 Microsoft.Kubernetes/ConnectedClusters
apiVersion リソース API のバージョン。 2024-01-01
name リソースの名前。 String (必須)
文字数制限: 1 から 63
有効な文字: 英数字、アンダースコア、ハイフン。
先頭と末尾には英数字を使用します。
location リソースが格納されている地理的な場所。 文字列 (必須)。
tags リソース タグ。 タグ名と値のディクショナリ。 「テンプレートのタグ」を参照してください。
extendedLocation 仮想マシンの拡張された場所。 ExtendedLocation
identity 接続されているクラスターの ID (構成されている場合)。
properties 接続されたクラスターのプロパティ。

ProvisionedClusterInstances

名前 説明
type リソースの種類 microsoft.hybridcontainerservice/provisionedclusterinstances
apiVersion リソース API のバージョン 2024-01-01
name リソース名 文字列 (必須)。 これを 既定から変更しないでください。
properties 接続されたクラスターのプロパティ。
extendedLocation クラスターの拡張された場所。 ExtendedLocation

ExtendedLocation

名前 説明
name 拡張された場所の ID。 string
type 拡張された場所の型。 CustomLocation

次の手順

AKS Arc の概要