配置 AKS 群集Configure an AKS cluster

在创建 AKS 群集的过程中,你可能需要自定义群集配置来满足你的需求。As part of creating an AKS cluster, you may need to customize your cluster configuration to suit your needs. 本文介绍了几个用于自定义 AKS 群集的选项。This article introduces a few options for customizing your AKS cluster.

OS 配置OS configuration

AKS 现在支持 Ubuntu 18.04 的正式发布 (GA) 版作为 kubernetes 版本高于 1.18 的群集的默认节点操作系统 (OS),对于低于 1.18 的版本,AKS Ubuntu 16.04 仍是默认的基础映像。AKS now supports Ubuntu 18.04 as the default node operating system (OS) in general availability (GA) for clusters in kubernetes versions higher than 1.18 For versions below 1.18, AKS Ubuntu 16.04 is still the default base image. 从 Kubernetes v1.18 及更高版本开始,默认基础映像是 AKS Ubuntu 18.04。From kubernetes v1.18 and higher, the default base is AKS Ubuntu 18.04.

重要

在 Kubernetes v1.18 或更高版本上创建的节点池默认使用 AKS Ubuntu 18.04 节点映像。Node pools created on Kubernetes v1.18 or greater default to AKS Ubuntu 18.04 node image. 低于 1.18 的受支持 Kubernetes 版本上的节点池会接收 AKS Ubuntu 16.04 作为节点映像,但在节点池 Kubernetes 版本更新到 v1.18 或更高版本后就会更新到 AKS Ubuntu 18.04Node pools on a supported Kubernetes version less than 1.18 receive AKS Ubuntu 16.04 as the node image, but will be updated to AKS Ubuntu 18.04 once the node pool Kubernetes version is updated to v1.18 or greater.

强烈建议在使用 1.18 或更高版本上创建的群集之前,在 AKS Ubuntu 18.04 节点池上测试工作负荷。It is highly recommended to test your workloads on AKS Ubuntu 18.04 node pools prior to using clusters on 1.18 or greater.

在新群集上使用 AKS Ubuntu 18.04 (GA)Use AKS Ubuntu 18.04 (GA) on new clusters

在 Kubernetes v1.18 或更高版本上创建的群集默认使用 AKS Ubuntu 18.04 节点映像。Clusters created on Kubernetes v1.18 or greater default to AKS Ubuntu 18.04 node image. 低于 1.18 的受支持 Kubernetes 版本上创建的节点池仍会接收 AKS Ubuntu 16.04 作为节点映像,但在群集或节点池 Kubernetes 版本更新到 v1.18 或更高后就会更新到 AKS Ubuntu 18.04Node pools on a supported Kubernetes version less than 1.18 will still receive AKS Ubuntu 16.04 as the node image, but will be updated to AKS Ubuntu 18.04 once the cluster or node pool Kubernetes version is updated to v1.18 or greater.

强烈建议在使用 1.18 或更高版本上创建的群集之前,在 AKS Ubuntu 18.04 节点池上测试工作负荷。It is highly recommended to test your workloads on AKS Ubuntu 18.04 node pools prior to using clusters on 1.18 or greater.

若要使用 AKS Ubuntu 18.04 节点映像创建群集,只需创建运行 Kubernetes v1.18 或更高版本的群集,如下所示To create a cluster using AKS Ubuntu 18.04 node image, simply create a cluster running kubernetes v1.18 or greater as shown below

az aks create --name myAKSCluster --resource-group myResourceGroup --kubernetes-version 1.18.14

备注

可通过以下 CLI cmdlet 查找有效的 Kubernetes 版本。We can find the valid kubernetes version with following CLI cmdlet. az aks get-versions --location chinaeast2 --output table

在现有的群集上使用 AKS Ubuntu 18.04 (GA)Use AKS Ubuntu 18.04 (GA) on existing clusters

在 Kubernetes v1.18 或更高版本上创建的群集默认使用 AKS Ubuntu 18.04 节点映像。Clusters created on Kubernetes v1.18 or greater default to AKS Ubuntu 18.04 node image. 低于 1.18 的受支持 Kubernetes 版本上创建的节点池仍会接收 AKS Ubuntu 16.04 作为节点映像,但在群集或节点池 Kubernetes 版本更新到 v1.18 或更高后就会更新到 AKS Ubuntu 18.04Node pools on a supported Kubernetes version less than 1.18 will still receive AKS Ubuntu 16.04 as the node image, but will be updated to AKS Ubuntu 18.04 once the cluster or node pool Kubernetes version is updated to v1.18 or greater.

强烈建议在使用 1.18 或更高版本上创建的群集之前,在 AKS Ubuntu 18.04 节点池上测试工作负荷。It is highly recommended to test your workloads on AKS Ubuntu 18.04 node pools prior to using clusters on 1.18 or greater.

如果群集或节点池已做好使用 AKS Ubuntu 18.04 节点映像的准备,则只需将其升级到 v1.18 或更高版本,如下所示。If your clusters or node pools are ready for AKS Ubuntu 18.04 node image, you can simply upgrade them to a v1.18 or higher as below.

az aks upgrade --name myAKSCluster --resource-group myResourceGroup --kubernetes-version 1.18.14

如果只想升级一个节点池,请执行以下命令:If you just want to upgrade just one node pool:

az aks nodepool upgrade -name ubuntu1804 --cluster-name myAKSCluster --resource-group myResourceGroup --kubernetes-version 1.18.14

在现有的群集上测试 AKS Ubuntu 18.04 (GA)Test AKS Ubuntu 18.04 (GA) on existing clusters

在 Kubernetes v1.18 或更高版本上创建的节点池默认使用 AKS Ubuntu 18.04 节点映像。Node pools created on Kubernetes v1.18 or greater default to AKS Ubuntu 18.04 node image. 低于 1.18 的受支持 Kubernetes 版本上创建的节点池仍会接收 AKS Ubuntu 16.04 作为节点映像,但在节点池 Kubernetes 版本更新到 v1.18 或更高后就会更新到 AKS Ubuntu 18.04Node pools on a supported Kubernetes version less than 1.18 will still receive AKS Ubuntu 16.04 as the node image, but will be updated to AKS Ubuntu 18.04 once the node pool Kubernetes version is updated to v1.18 or greater.

强烈建议在升级生产节点池之前,在 AKS Ubuntu 18.04 节点池上测试工作负荷。It is highly recommended to test your workloads on AKS Ubuntu 18.04 node pools prior to upgrading your production node pools.

若要使用 AKS Ubuntu 18.04 节点映像创建节点池,只需创建运行 Kubernetes v1.18 或更高版本的节点池。To create a node pool using AKS Ubuntu 18.04 node image, simply create a node pool running kubernetes v1.18 or greater. 群集控制平面也至少需要位于 v1.18 或更高版本上,但其他节点池可以保留在较旧的 Kubernetes 版本上。Your cluster control plane needs to be at least on v1.18 or greater as well but your other node pools can remain on an older kubernetes version. 下面,我们将首先升级控制平面,然后使用将会接收新节点映像 OS 版本的 v1.18 来创建新节点池。Below we are first upgrading the control plane and then creating a new node pool with v1.18 that will receive the new node image OS version.

az aks upgrade --name myAKSCluster --resource-group myResourceGroup --kubernetes-version 1.18.14 --control-plane-only

az aks nodepool add --name ubuntu1804 --cluster-name myAKSCluster --resource-group myResourceGroup --kubernetes-version 1.18.14

临时 OSEphemeral OS

默认情况下,Azure 会自动将虚拟机的操作系统磁盘复制到 Azure 存储,以避免在 VM 需要重定位到另一台主机时丢失数据。By default, Azure automatically replicates the operating system disk for an virtual machine to Azure storage to avoid data loss should the VM need to be relocated to another host. 但是,由于容器并未设计为保留本地状态,因此该行为提供的价值有限且存在一些缺点,其中包括节点预配速度较慢、读/写延迟较高。However, since containers aren't designed to have local state persisted, this behavior offers limited value while providing some drawbacks, including slower node provisioning and higher read/write latency.

相比而言,临时 OS 磁盘只存储在主机上,就像临时磁盘一样。By contrast, ephemeral OS disks are stored only on the host machine, just like a temporary disk. 这样的读/写延迟较低,且节点缩放和群集升级速度较快。This provides lower read/write latency, along with faster node scaling and cluster upgrades.

与临时磁盘类似,临时 OS 磁盘包含在虚拟机的价格中,因此不会产生额外的存储成本。Like the temporary disk, an ephemeral OS disk is included in the price of the virtual machine, so you incur no additional storage costs.

重要

如果用户未显式请求用于 OS 的托管磁盘,则在可能的情况下,AKS 会针对给定的 nodepool 配置默认使用临时 OS。When a user does not explicitly request managed disks for the OS, AKS will default to ephemeral OS if possible for a given nodepool configuration.

使用临时 OS 时,OS 磁盘必须适合 VM 缓存。When using ephemeral OS, the OS disk must fit in the VM cache. VM 缓存的大小在 Azure 文档中以括号的形式提供,位于 IO 吞吐量旁边(“以 GiB 为单位的缓存大小”)。The sizes for VM cache are available in the Azure documentation in parentheses next to IO throughput ("cache size in GiB").

以 AKS 默认 VM 大小 Standard_DS2_v2 和默认 OS 磁盘大小 100GB 为例,此 VM 大小支持临时 OS,但只有 86GB 的缓存大小。Using the AKS default VM size Standard_DS2_v2 with the default OS disk size of 100GB as an example, this VM size supports ephemeral OS but only has 86GB of cache size. 如果用户未进行显式指定,则此配置默认为托管磁盘。This configuration would default to managed disks if the user does not specify explicitly. 如果用户显式请求了临时 OS,则用户会收到验证错误。If a user explicitly requested ephemeral OS, they would receive a validation error.

如果用户请求 OS 磁盘大小为 60GB 的同一 Standard_DS2_v2,则此配置将默认为临时 OS:请求的 60GB 大小小于最大缓存大小 86GB。If a user requests the same Standard_DS2_v2 with a 60GB OS disk, this configuration would default to ephemeral OS: the requested size of 60GB is smaller than the maximum cache size of 86GB.

将 Standard_D8s_v3 与 100GB OS 磁盘配合使用时,此 VM 大小支持临时 OS,有 200GB 的缓存空间。Using Standard_D8s_v3 with 100GB OS disk, this VM size supports ephemeral OS and has 200GB of cache space. 如果用户未指定 OS 磁盘类型,则默认情况下,nodepool 会收到临时 OS。If a user does not specify the OS disk type, the nodepool would receive ephemeral OS by default.

临时 OS 至少需要 2.15.0 版的 Azure CLI。Ephemeral OS requires at least version 2.15.0 of the Azure CLI.

在新群集上使用临时 OSUse Ephemeral OS on new clusters

配置群集,以便在创建群集时使用临时 OS 磁盘。Configure the cluster to use Ephemeral OS disks when the cluster is created. 使用 --node-osdisk-type 标志将临时 OS 设置为新群集的 OS 磁盘类型。Use the --node-osdisk-type flag to set Ephemeral OS as the OS disk type for the new cluster.

az aks create --name myAKSCluster --resource-group myResourceGroup -s Standard_DS3_v2 --node-osdisk-type Ephemeral

若要使用通过网络附加的 OS 磁盘来创建常规群集,可以指定 --node-osdisk-type=ManagedIf you want to create a regular cluster using network-attached OS disks, you can do so by specifying --node-osdisk-type=Managed. 还可以选择添加更多的临时 OS 节点池,如下所示。You can also choose to add more ephemeral OS node pools as per below.

在现有群集上使用临时 OSUse Ephemeral OS on existing clusters

配置新节点池,以使用临时 OS 磁盘。Configure a new node pool to use Ephemeral OS disks. 使用 --node-osdisk-type 标志将 OS 磁盘类型设置为该节点池的 OS 磁盘类型。Use the --node-osdisk-type flag to set as the OS disk type as the OS disk type for that node pool.

az aks nodepool add --name ephemeral --cluster-name myAKSCluster --resource-group myResourceGroup -s Standard_DS3_v2 --node-osdisk-type Ephemeral

重要

如果使用临时 OS,可以部署不超过 VM 缓存大小的 VM 和实例映像。With ephemeral OS you can deploy VM and instance images up to the size of the VM cache. 在使用 AKS 的情况下,默认节点 OS 磁盘配置使用 128GB,这意味着所需 VM 大小的缓存大于 128GB。In the AKS case, the default node OS disk configuration uses 128GB, which means that you need a VM size that has a cache larger than 128GB. 默认 Standard_DS2_v2 的缓存大小为 86GB,不够大。The default Standard_DS2_v2 has a cache size of 86GB, which is not large enough. Standard_DS3_v2 的缓存大小为 172GB,足够大。The Standard_DS3_v2 has a cache size of 172GB, which is large enough. 还可以通过使用 --node-osdisk-size 来减小 OS 磁盘的默认大小。You can also reduce the default size of the OS disk by using --node-osdisk-size. AKS 映像的最小大小为 30GB。The minimum size for AKS images is 30GB.

若要使用通过网络附加的 OS 磁盘来创建节点池,可以指定 --node-osdisk-type ManagedIf you want to create node pools with network-attached OS disks, you can do so by specifying --node-osdisk-type Managed.

自定义资源组名称Custom resource group name

在 Azure 中部署 Azure Kubernetes 服务群集时,会为工作器节点创建第二个资源组。When you deploy an Azure Kubernetes Service cluster in Azure, a second resource group gets created for the worker nodes. 默认情况下,AKS 会将节点资源组命名为 MC_resourcegroupname_clustername_location,但你也可以提供自己的名称。By default, AKS will name the node resource group MC_resourcegroupname_clustername_location, but you can also provide your own name.

若要指定自己的资源组名称,请安装 aks-preview Azure CLI 扩展版本 0.3.2 或更高版本。To specify your own resource group name, install the aks-preview Azure CLI extension version 0.3.2 or later. 使用 Azure CLI 时,通过 az aks create 命令的 --node-resource-group 参数为资源组指定自定义名称。Using the Azure CLI, use the --node-resource-group parameter of the az aks create command to specify a custom name for the resource group. 如果使用 Azure 资源管理器模板部署 AKS 群集,可以使用 nodeResourceGroup 属性定义资源组名称。If you use an Azure Resource Manager template to deploy an AKS cluster, you can define the resource group name by using the nodeResourceGroup property.

az aks create --name myAKSCluster --resource-group myResourceGroup --node-resource-group myNodeResourceGroup

第二个资源组由订阅中的 Azure 资源提供程序自动创建。The secondary resource group is automatically created by the Azure resource provider in your own subscription. 只有创建了群集,才能指定自定义资源组名称。You can only specify the custom resource group name when the cluster is created.

请注意,对于节点资源组,不能执行以下操作:As you work with the node resource group, keep in mind that you can't:

  • 不能为节点资源组指定现有资源组。Specify an existing resource group for the node resource group.
  • 为节点资源组指定不同的订阅。Specify a different subscription for the node resource group.
  • 创建群集后更改节点资源组名称。Change the node resource group name after the cluster has been created.
  • 不能为节点资源组内的受管理资源指定名称。Specify names for the managed resources within the node resource group.
  • 不能修改或删除节点资源组内受管理资源中由 Azure 创建的标记。Modify or delete Azure-created tags of managed resources within the node resource group.

后续步骤Next steps