快速入门:使用 PowerShell 设置 Azure Stack HCI 上的 Azure Kubernetes 服务主机Quickstart: Set up an Azure Kubernetes Service host on Azure Stack HCI using PowerShell

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

在本快速入门中,你将了解如何使用 PowerShell 设置 Azure Stack HCI 上的 Azure Kubernetes 服务主机。In this quickstart, you'll learn how to set up an Azure Kubernetes Service host on Azure Stack HCI using PowerShell. 若要改为使用 Windows Admin Center,请参阅使用 Windows Admin Center 进行设置To instead use Windows Admin Center, see Set up with Windows Admin Center.

准备阶段Before you begin

在开始之前,请确保你已有一个 2-4 节点的 Azure Stack HCI 群集或单节点 Azure Stack HCI。Before you begin, make sure you 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. 如果没有,请按照 Azure Stack HCI 注册页中的说明进行操作。If you don't, follow instructions on the Azure Stack HCI registration page.

步骤 1:下载并安装 AksHci PowerShell 模块Step 1: Download and install the AksHci PowerShell module

请从 Azure Stack HCI 上的 Azure Kubernetes 服务注册页下载 AKS-HCI-Public=Preview-Oct-2020Download the AKS-HCI-Public=Preview-Oct-2020 from the Azure Kubernetes Service on Azure Stack HCI registration page. zip 文件 AksHci.Powershell.zip 包含 PowerShell 模块。The zip file AksHci.Powershell.zip contains the PowerShell module.

如果以前使用 PowerShell 或 Windows Admin Center 在 Azure Stack HCI 上安装了 Azure Kubernetes 服务,请在继续操作之前运行以下命令。If you have previously installed Azure Kubernetes Service on Azure Stack HCI using PowerShell or Windows Admin Center, run the following command before proceeding.

Uninstall-AksHci

关闭 PowerShell 窗口。Close all PowerShell windows. 删除 %systemdrive%\program files\windowspowershell\modules 路径中的 AksHci、AksHci.Day2 和 MSK8sDownloadAgent 的任何现有目录。Delete any existing directories for AksHci, AksHci.Day2, and MSK8sDownloadAgent located in the path %systemdrive%\program files\windowspowershell\modules. 完成此操作后,便可提取新 zip 文件的内容。Once this is done, you can extract the contents of the new zip file. 请确保在正确的位置 (%systemdrive%\program files\windowspowershell\modules) 提取 zip 文件。Make sure to extract the zip file in the correct location (%systemdrive%\program files\windowspowershell\modules).

Import-Module AksHci

运行上述命令后,关闭所有 PowerShell 窗口,然后重新打开管理会话,以运行以下步骤中的命令。After running the above command, close all PowerShell windows and reopen an administrative session to run the commands in the following steps.

步骤 2:准备要部署的计算机Step 2: Prepare your machine(s) for deployment

在每个物理节点上运行检查,以查看所有要求是否都已得到满足,以便安装 Azure Stack HCI 上的 Azure Kubernetes 服务。Run checks on every physical node to see if all the requirements are satisfied to install Azure Kubernetes Service on Azure Stack HCI.

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

Initialize-AksHciNode

检查完以后,你会看到以绿色文本显示的“已完成”。When the checks are finished, you'll see "Done" displayed in green text.

步骤 3:配置部署Step 3: Configure your deployment

设置 Azure Kubernetes 服务主机的配置设置。Set the configuration settings for the Azure Kubernetes Service host. 对于 2-4 节点的 Azure Stack HCI 群集,必须在 -deploymentTypewssdImageDircloudConfigLocation 参数中指定 MultiNodeFor a 2-4 node Azure Stack HCI cluster, you must specify MultiNode in the -deploymentType, the wssdImageDir and cloudConfigLocation parameters. 对于 1 节点的 Azure Stack HCI 群集,所有参数都是可选的,并设置为其默认值。For a 1 node Azure Stack HCI cluster, all parameters are optional and set to their default values. 但是,为了获得最佳性能,建议使用 2-4 节点的 Azure Stack HCI 群集部署。However, for optimal performance, we recommend using a 2-4 node Azure Stack HCI cluster deployment.

使用以下命令配置部署。Configure your deployment with the following command.

Set-AksHciConfig [-deploymentType {SingleNode, MultiNode}]
                 [-wssdImageDir]
                 [-cloudConfigLocation]
                 [-nodeConfigLocation]
                 [-vnetName]
                 [-controlPlaneVmSize]
                 [-loadBalancerVmSize]
                 [-sshPublicKey]
                 [-vipPoolStartIp]
                 [-vipPoolEndIp]
                 [-macPoolStart]
                 [-macPoolEnd]
                 [-vlanID]
                 [-cloudServiceCidr]
                 [-wssdDir]
                 [-akshciVersion]
                 [-vnetType]
                 [-nodeAgentPort]
                 [-nodeAgentAuthorizerPort]
                 [-clusterRoleName]
                 [-skipHostLimitChecks]
                 [-insecure]
                 [-skipUpdates]
                 [-forceDnsReplication]

可选参数Optional parameters

-deploymentType

部署类型。The deployment type. 接受的值:SingleNode、MultiNode。Accepted values: SingleNode, MultiNode. 默认值为 SingleNode。Defaults to SingleNode.

-wssdImageDir

Azure Stack HCI 上的 Azure Kubernetes 服务将在其中存储 VHD 映像的目录的路径。The path to the directory where Azure Kubernetes Service on Azure Stack HCI will store its VHD images. 对于单节点部署,默认值为 %systemdrive%\wssdimagestoreDefaults to %systemdrive%\wssdimagestore for single node deployments. 对于多节点部署,必须指定此参数。For multi-node deployments, this parameter must be specified. 路径必须指向共享的存储路径(例如 C:\ClusterStorage\Volume2\ImageStore )或 SMB 共享(例如 \\FileShare\ImageStore)。The path must point to a shared storage path such as C:\ClusterStorage\Volume2\ImageStore or an SMB share such as \\FileShare\ImageStore.

-cloudConfigLocation

云代理将存储其配置的位置。The location where the cloud agent will store its configuration. 对于单节点部署,默认值为 %systemdrive%\wssdimagestoreDefaults to %systemdrive%\wssdimagestore for single node deployments. 此位置可以与上面的 -wssdImageDir 路径相同。The location can be the same as the path of -wssdImageDir above. 对于多节点部署,必须指定此参数。 For *multi-node deployments, this parameter must be specified*.

-nodeConfigLocation

节点代理将存储其配置的位置。The location where the node agents will store their configuration. 这必须是一个本地路径。This must be a local path.

-vnetName

要将虚拟机与之连接的虚拟交换机的名称。The name of the virtual switch to connect the virtual machines to. 默认为“外部”名称。Defaults to “External” name. 如果该交换机不存在,则会创建它。The switch will be created if it does not exist.

-controlPlaneVmSize

要为控制平面创建的 VM 的大小。The size of the VM to create for the control plane. 若要获取可用 VM 大小的列表,请运行 Get-AksHciVmSizeTo get a list of available VM sizes, run Get-AksHciVmSize.

-loadBalancerVmSize

要为负载均衡器 VM 创建的 VM 的大小。The size of the VM to create for the Load Balancer VMs. 若要获取可用 VM 大小的列表,请运行 Get-AksHciVmSizeTo get a list of available VM sizes, run Get-AksHciVmSize.

-sshPublicKey

SSH 公钥文件的路径。Path to an SSH public key file. 使用此公钥,你将能够登录到 Azure Stack HCI 部署上的 Azure Kubernetes 服务创建的任何 VM。Using this public key, you will be able to log in to any of the VMs created by the Azure Kubernetes Service on Azure Stack HCI deployment. 如果未提供任何密钥,我们将在 %systemdrive%\Users\<username>\.ssh\id_rsa.pub 下查找一个密钥。If no key is provided, we will look for one under %systemdrive%\Users\<username>\.ssh\id_rsa.pub. 如果文件不存在,将生成并使用上述位置的 SSH 密钥对。If file does not exist, an SSH key pair in the above location will be generated and used.

-vipPoolStartIp

使用 VIP 池进行部署时,此参数将指定池的网络开始 IP。When using VIP pools for your deployment, this parameter specifies the network start of the pool. 默认为无。Default is none.

-vipPoolEndIp

使用 VIP 池进行部署时,此参数将指定池的网络结束 IP。When using VIP pools for your deployment, this parameter specifies the network end of the pool. 默认为无。Default is none.

-macPoolStart

这用于指定你希望用于 Azure Kubernetes 服务主机 VM 的 MAC 池的 MAC 地址开头。This is used to specify the start of the MAC address of the MAC pool that you wish to use for the Azure Kubernetes Service host VM. MAC 地址的语法要求第一个字节的最小有效位应始终为 0,第一个字节应始终是偶数(即 00、02、04、06...)。典型的 MAC 地址可能如下所示:02:1E:2B:78:00:00。The syntax for the MAC address requires that the least significant bit of the first byte should always be 0, and the first byte should always be an even number (i.e. 00, 02, 04, 06...). A typical MAC address can look like: 02:1E:2B:78:00:00. 默认为无。Default is none.

-macPoolEnd

这用于指定你希望用于 Azure Kubernetes 服务主机 VM 的 MAC 池的 MAC 地址结尾。This is used to specify the end of the MAC address of the MAC pool that you wish to use for the Azure Kubernetes Service host VM. MAC 地址的语法要求第一个字节的最小有效位应始终为 0,第一个字节应始终是偶数(即 00、02、04、06...)。作为 -macPoolEnd 传递的地址的第一个字节应与作为 -macPoolStart 传递的地址的第一个字节相同。The syntax for the MAC address requires that the least significant bit of the first byte should always be 0, and the first byte should always be an even number (i.e. 00, 02, 04, 06...). The first byte of the address passed as the -macPoolEnd should be the same as the first byte of the address passed as the -macPoolStart. 默认为无。Default is none.

-vlandID

这可以用来指定网络 VLAN ID。This can be used to specify a network VLAN ID. Azure Kubernetes 服务主机和 Kubernetes 群集 VM 网络适配器将用提供的 VLAN ID 进行标记。Azure Kubernetes Service host and Kubernetes cluster VM network adapters will be tagged with the provided VLAN ID. 默认为无。Default is none.

cloudServiceCidr

这可用于提供一个静态 IP/网络前缀来分配给 MOC CloudAgent 服务。This can be used to provide a static IP/network prefix to be assigned to the MOC CloudAgent service. 应使用 CIDR 格式提供此值。This value should be provided using the CIDR format. (示例:192.168.1.2/16)。(Example: 192.168.1.2/16). 默认为无。Default is none.

-wssdDir

这是用于存储小文件的模块的工作目录。This is a working directory for the module to use for storing small files. 默认为 %PROGRAMFILES%\AksHci ,大多数部署不应进行更改。Defaults to %PROGRAMFILES%\AksHci and should not be changed for most deployments.

-akshciVersion

要部署的 Azure Stack HCI 上的 Azure Kubernetes 服务的版本。The version of Azure Kubernetes Service on Azure Stack HCI that you want to deploy. 默认值为最新版本。The default is the latest version.

-vnetType

要连接或创建的虚拟交换机的类型。The type of virtual switch to connect to or create. 此值默认为“外部”交换机类型。This defaults to “External” switch type.

-nodeAgentPort

节点代理应侦听的 TCP/IP 端口号。The TCP/IP port number that nodeagents should listen on. 默认为 45000。Defaults to 45000.

-nodeAgentAuthorizerPort

节点代理应当将它用于其授权端口的 TCP/IP 端口号。The TCP/IP port number that nodeagents should use for their authorization port. 默认为 45001。Defaults to 45001.

-clusterRoleName

这指定在群集中将云代理创建为一般服务时要使用的名称。This specifies the name to use when creating cloudagent as a generic service within the cluster. 这默认设置为采用前缀 ca- 和一个 guid 后缀的唯一名称(例如:“ca-9e6eb299-bc0b-4f00-9fd7-942843820c26”)This defaults to a unique name with a prefix of ca- and a guid suffix (for example: “ca-9e6eb299-bc0b-4f00-9fd7-942843820c26”)

-skipHostLimitChecks

在允许部署继续进行之前,请求脚本跳过它用于确认内存和磁盘空间是否可用的所有检查。Requests the script to skip any checks it does to confirm memory and disk space is available before allowing the deployment to proceed.

-insecure

在不安全模式(无 TLS 安全连接)下部署 Azure Stack HCI 上的 Azure Kubernetes 服务组件,例如云代理和节点代理。Deploys Azure Kubernetes Service on Azure Stack HCI components such as cloudagent and nodeagent(s) in insecure mode (no TLS secured connections).  建议不要在生产环境中使用不安全模式。  It is not recommended to use insecure mode in production environments.

-skipUpdates

如果要跳过任何可用的更新,请使用此标志。Use this flag if you want to skip any updates available.

-forceDnsReplication

在某些系统上,DNS 复制最多可能需要一小时。DNS replication can take up to an hour on some systems. 这会导致部署速度缓慢。This will cause the deployment to be slow. 如果遇到此问题,你会看到 Install-AksHci 停滞在循环中。If you hit this issue, you'll see that the Install-AksHci will be stuck in a loop. 若要解决此问题,请尝试使用此标志。To get past this issue, try to use this flag. -forceDnsReplication 标志不是有保证的修补方法。The -forceDnsReplication flag is not a guaranteed fix. 如果该标志背后的逻辑失败,则会隐藏该错误,并且命令将继续执行,如同未提供该标志一样。If the logic behind the flag fails, the error will be hidden, and the command will carry on as if the flag was not provided.

重置 Azure Stack HCI 上的 Azure Kubernetes 服务的配置Reset the Azure Kubernetes Service on Azure Stack HCI configuration

若要重置 Azure Stack HCI 上的 Azure Kubernetes 服务的配置,请运行以下命令。To reset the Azure Kubernetes Service on Azure Stack HCI configuration, run the following command. 单独运行此命令会将配置重置为默认值。Running this command on its own will reset the configuration to default values.

Set-AksHciConfig

步骤 4:启动新部署Step 4: Start a new deployment

配置你的部署后,你必须启动部署。After you've configured your deployment, you must start deployment. 这会在 Azure Stack HCI 代理/服务和 Azure Kubernetes 服务主机上安装 Azure Kubernetes 服务。This will install the Azure Kubernetes Service on Azure Stack HCI agents/services and the Azure Kubernetes Service host.

若要开始部署,请运行以下命令。To begin deployment, run the following command.

Install-AksHci

验证已部署的 Azure Kubernetes 服务主机Verify your deployed Azure Kubernetes Service host

若要确保 Azure Kubernetes 服务主机已部署,请运行以下命令。To ensure that your Azure Kubernetes Service host was deployed, run the following command. 部署 Kubernetes 群集后,还可以使用相同的命令获取这些群集。You will also be able to get Kubernetes clusters using the same command after deploying them.

Get-AksHciCluster

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

若要使用 kubectl 访问 Azure Kubernetes 服务主机或 Kubernetes 群集,请运行以下命令。To access your Azure Kubernetes Service host or Kubernetes cluster 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.

获取日志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

重新安装 Azure Stack HCI 上的 Azure Kubernetes 服务Reinstall Azure Kubernetes Service on Azure Stack HCI

重新安装 Azure Stack HCI 上的 Azure Kubernetes 服务会删除所有 Kubernetes 群集(如果有)以及 Azure Kubernetes 服务主机。Reinstalling Azure Kubernetes Service on Azure Stack HCI will remove all of your Kubernetes clusters if any, and the Azure Kubernetes Service host. 它还会从节点中卸载 Azure Stack HCI 代理和服务上的 Azure Kubernetes 服务。It will also uninstall the Azure Kubernetes Service on Azure Stack HCI agents and services from the nodes. 然后,它会重复原始安装过程步骤,直到重新创建主机。It will then go back through the original install process steps until the host is recreated. 你通过 Set-AksHciConfig 配置的 Azure Stack HCI 上的 Azure Kubernetes 服务配置和下载的 VHDX 映像将保留。The Azure Kubernetes Service on Azure Stack HCI configuration that you configured via Set-AksHciConfig and the downloaded VHDX images are preserved.

若要重新安装 Azure Stack HCI 上的 Azure Kubernetes 服务,请运行以下命令。To reinstall Azure Kubernetes Service on Azure Stack HCI, run the following command.

Restart-AksHci

删除 Azure Stack HCI 上的 Azure Kubernetes 服务Remove Azure Kubernetes Service on Azure Stack HCI

若要删除 Azure Stack HCI 上的 Azure Kubernetes 服务,请运行以下命令。To remove Azure Kubernetes Service on Azure Stack HCI, run the following command.

Uninstall-AksHci

后续步骤Next steps