快速入门:使用 Windows PowerShell 在 Azure Stack HCI 上创建 Kubernetes 群集Quickstart: Create Kubernetes clusters on Azure Stack HCI using Windows PowerShell

适用于:Azure Stack HCIApplies to: Azure Stack HCI

本快速入门介绍如何使用 Windows PowerShell 在 Azure Stack HCI 上创建 Kubernetes 群集。In this quickstart, you learn how to use Windows PowerShell to create a Kubernetes cluster on Azure Stack HCI. 若要改为使用 Windows Admin Center,请参阅使用 Windows Admin Center 设置 Azure Stack HCI 上的 Azure Kubernetes 服务To instead use Windows Admin Center, see Set up Azure Kubernetes Service on Azure Stack HCI using Windows Admin Center.

在开始之前Before you begin

在开始之前,请确保:Before you begin, make sure you:

  • 具有一个 2-4 节点的 Azure Stack HCI 群集或单节点 Azure Stack HCI。Have a 2-4 node Azure Stack HCI cluster or a single node Azure Stack HCI. 建议使用 2-4 节点的 Azure Stack HCI 群集。We recommend having a 2-4 node Azure Stack HCI cluster. 如果没有,请按照此处有关如何创建的说明进行操作。If you don't, follow instructions on how to create one here.
  • 设置了 Azure Stack Kubernetes 主机。Have an Azure Stack Kubernetes host set up. 如果没有,请按照此处有关如何设置的说明进行操作。If you don't, follow instructions on how to set one up here.

步骤 1:创建 Kubernetes 群集Step 1: Create a Kubernetes cluster

安装 Azure Kubernetes 服务主机之后,便准备好部署 Kubernetes 群集。After installing your Azure Kubernetes Service host, you are ready to deploy a Kubernetes cluster.

以管理员身份打开 PowerShell 并运行以下命令。Open PowerShell as an administrator and run the following command.

New-AksHciCluster -clusterName
                 [-kubernetesVersion]
                 [-controlPlaneNodeCount]
                 [-linuxNodeCount]
                 [-windowsNodeCount]
                 [-controlPlaneVmSize]
                 [-loadBalancerVmSize]
                 [-linuxNodeVmSize]
                 [-windowsNodeVmSize]

必需的参数Required parameters

-clusterName

Kubernetes 群集的字母数字名称。The alphanumeric name of your Kubernetes cluster.

可选参数Optional parameters

-kubernetesVersion

要部署的 Kubernetes 的版本。The version of Kubernetes that you want to deploy. 默认值为 v1.18.6。Default is v1.18.6. 若要获取可用版本的列表,请运行 Get-AksHciKubernetesVersionTo get a list of available versions, run Get-AksHciKubernetesVersion.

-controlPlaneNodeCount

控制平面中的节点数。The number of nodes in your control plane. 默认值为 1。Default is 1.

-linuxNodeCount

Kubernetes 群集中的 Linux 节点数。The number of Linux nodes in your Kubernetes cluster. 默认值为 1。Default is 1.

-windowsNodeCount

Kubernetes 群集中的 Windows 节点数。The number of Windows nodes in your Kubernetes cluster. 默认为 0。Default is 0.

-controlPlaneVmSize

控制平面 VM 的大小。The size of your control plane VM. 默认值为 Standard_A2_v2。Default is Standard_A2_v2. 若要获取可用 VM 大小的列表,请运行 Get-AksHciVmSizeTo get a list of available VM sizes, run Get-AksHciVmSize.

-loadBalancerVmSize

负载均衡器 VM 的大小。The size of your load balancer VM. 默认值为 Standard_A2_V2。Default is Standard_A2_V2. 若要获取可用 VM 大小的列表,请运行 Get-AksHciVmSizeTo get a list of available VM sizes, run Get-AksHciVmSize.

-linuxNodeVmSize

Linux 节点 VM 的大小。The size of your Linux Node VM. 默认值为 Standard_K8S3_v1。Default is Standard_K8S3_v1. 若要获取可用 VM 大小的列表,请运行 Get-AksHciVmSizeTo get a list of available VM sizes, run Get-AksHciVmSize.

-windowsNodeVmSize

Windows 节点 VM 的大小。The size of your Windows Node VM. 默认值为 Standard_K8S3_v1。Default is Standard_K8S3_v1. 若要获取可用 VM 大小的列表,请运行 Get-AksHciVmSizeTo get a list of available VM sizes, run Get-AksHciVmSize.

检查部署的群集Check your deployed clusters

若要获取已部署 Azure Kubernetes 服务主机和 Kubernetes 群集的列表,请运行以下命令。To get a list of your deployed Azure Kubernetes Service host and Kubernetes clusters, run the following command.

Get-AksHciCluster

步骤 2:缩放 Kubernetes 群集Step 2: Scale a Kubernetes cluster

如果需要纵向扩展或缩减群集,可以更改控制平面节点、Linux 工作器节点或 Windows 工作器节点的数量。If you need to scale your cluster up or down, you can change the number of control plane nodes, Linux worker nodes, or Windows worker nodes.

若要缩放控制平面节点,请运行以下命令。To scale control plane nodes, run the following command.

Set-AksHciClusterNodeCount -clusterName
                           -controlPlaneNodeCount

若要缩放工作器节点,请运行以下命令。To scale the worker nodes, run the following command.

Set-AksHciClusterNodeCount -clusterName
                           -linuxNodeCount
                           -windowsNodeCount

控制平面节点和工作器节点必须单独缩放。The control plane nodes and the worker nodes must be scaled independently.

步骤 3:升级 Kubernetes 版本Step 3: Upgrade Kubernetes version

若要查看正在运行的当前 Kubernetes 版本,请运行以下命令。To see the current Kubernetes version you're running, run the following command.

Get-AksHciKubernetesVersion

若要升级到下一个 Kubernetes 版本,请运行以下命令。To upgrade to the next Kubernetes version, run the following command.

Update-AksHciCluster -clusterName

如果要使用 Windows 节点,所需的最低版本为 v1.1.8.6。If you want to use Windows nodes, the minimum required version is v1.1.8.6.

步骤 4:使用 kubectl 访问群集Step 4: Access your clusters using kubectl

若要使用 kubectl 访问 Kubernetes 群集,请运行以下命令。To access your Kubernetes clusters using kubectl, run the following command. 这将使用指定群集的 kubeconfig 文件作为 kubectl 的默认 kubeconfig 文件。This will use the specified cluster's kubeconfig file as the default kubeconfig file for kubectl.

Get-AksHciCredential -clusterName
                     [-outputLocation]

必需参数Required Parameters

clusterName

群集的名称。The name of the cluster.

可选参数Optional Parameters

outputLocation

要下载 kubeconfig 的目标位置。The location were you want the kubeconfig downloaded. 默认值为 %USERPROFILE%\.kubeDefault is %USERPROFILE%\.kube.

删除 Kubernetes 群集Delete a Kubernetes cluster

如果需要删除 Kubernetes 群集,请运行以下命令。If you need to delete a Kubernetes cluster, run the following command.

Remove-AksHciCluster -clusterName

获取日志Get logs

若要从所有 Pod 获取日志,请运行以下命令。To get logs from your all your pods, run the following command. 此命令将在路径 C:\wssd\akshcilogs 中创建名为 akshcilogs 的输出压缩文件夹。This command will create an output zipped folder called akshcilogs in the path C:\wssd\akshcilogs.

Get-AksHciLogs

本快速入门介绍了如何使用 PowerShell 创建、缩放和升级 Kubernetes 群集。In this quickstart, you learned how to create, scale, and upgrade a Kubernetes cluster with PowerShell.

后续步骤Next steps