为 Azure Stack HCI 和 Windows Server 上的 Azure Kubernetes 服务 (AKS) 中的群集创建和管理多个节点池
在 Azure Stack HCI 和 Windows Server 上的 Azure Kubernetes 服务 (AKS) 中,采用相同配置的节点分组成节点池。 这些节点池包含运行应用程序的底层 VM。
注意
利用此功能可以更好地控制如何创建和管理多个节点池。 因此,需要使用单独的命令来执行创建/更新/删除操作。 以前,通过 New-AksHciCluster 或 Set-AksHciCluster 的群集操作是创建/缩放具有 Windows 节点池和 Linux 节点池的群集的唯一选项。 此功能为需要使用节点池命令 New-AksHciNodePool、Set-AksHciNodePool、Get-AksHciNodePool 和 Remove-AksHciNodePool 在单个节点池上执行操作的节点池公开单独的操作集。
本文介绍如何在 Azure Stack HCI 和 Windows Server 上的 AKS 群集中创建和管理多个节点池。
在开始之前
建议安装最新版本 1.1.6。 如果已安装 PowerShell 模块,请运行以下命令找到该版本。
Get-Command -Module AksHci
如果需要更新,请遵照此处的说明操作。
创建 Azure Stack HCI 和 Windows Server 上的 AKS 群集
首先,创建包含单个节点池的 Azure Stack HCI 和 Windows Server 上的 AKS 群集。 以下示例使用 New-AksHciCluster 命令创建一个新的 Kubernetes 群集,该群集有一个名为“linuxnodepool”的 Linux 节点池,其中包含 1 个节点。 如果已使用旧版 Azure Stack HCI 和 Windows Server 上的 AKS 部署了群集,并且希望继续使用旧部署,则可以跳过此步骤。 仍可使用一组新的节点池命令将更多节点池添加到现有群集。
New-AksHciCluster -name mycluster -nodePoolName linuxnodepool -nodeCount 1 -osType linux
注意
仍将支持 New-AksHciCluster
的旧参数集。 但未来版本将弃用它。
添加节点池
在上一步骤中创建的名为“mycluster”的群集包含单个节点池。 可以使用 New-AksHciNodePool 命令将第二个节点池添加到现有群集。 以下示例创建具有一个节点且名为 windowsnodepool 的 Windows 节点池。 请确保节点池的名称与另一个现有节点池不同。
New-AksHciNodePool -clusterName mycluster -name windowsnodepool -count 1 -osType windows
获取节点池的配置信息
若要查看节点池的配置信息,请使用 Get-AksHciNodePool 命令。
Get-AksHciNodePool -clusterName mycluster
示例输出
ClusterName : mycluster
NodePoolName : linuxnodepool
Version : v1.20.7
OsType : Linux
NodeCount : 1
VmSize : Standard_K8S3_v1
Phase : Deployed
ClusterName : mycluster
NodePoolName : windowsnodepool
Version : v1.20.7
OsType : Windows
NodeCount : 1
VmSize : Standard_K8S3_v1
Phase : Deployed
若要查看某个特定节点池的配置信息,请使用 Get-AksHciNodePool 中的 -name
参数
Get-AksHciNodePool -clusterName mycluster -name linuxnodepool
示例输出
ClusterName : mycluster
NodePoolName : linuxnodepool
Version : v1.20.7
OsType : Linux
NodeCount : 1
VmSize : Standard_K8S3_v1
Phase : Deployed
Get-AksHciNodePool -clusterName mycluster -name windowsnodepool
示例输出
ClusterName : mycluster
NodePoolName : windowsnodepool
Version : v1.20.7
OsType : Windows
NodeCount : 1
VmSize : Standard_K8S3_v1
Phase : Deployed
注意
如果使用 New-AksHciCluster
中的新参数集部署群集,然后运行 Get-AksHciCluster
来获取群集信息,则输出中的字段 WindowsNodeCount
和 LinuxNodeCount
将返回 0
。 要获取每个节点池中的准确节点数,请使用具有指定群集名称的命令 Get-AksHciNodePool
。
缩放节点池
可以纵向扩展或缩减节点池中的节点数。
若要缩放节点池中的节点数,请使用 Set-AksHciNodePool 命令。 以下示例在名为“mycluster”的群集中,将名为“linuxnodepool”的节点池中的节点数缩放为 3 。
Set-AksHciNodePool -clusterName mycluster -name linuxnodepool -count 3
缩放控制平面节点数
控制平面节点未更改。 创建、缩放和删除它们的方式保持不变。 仍将使用 New-AksHciCluster 命令来部署控制平面节点,该命令的参数 controlPlaneNodeCount
和 controlPlaneVmSize
默认值分别为 1 和 Standard_A4_V2(如果未指定任何值)。
当应用程序的工作负载需求改变时,可能需要缩放控制平面节点。 若要缩放控制平面节点,请使用 Set-AksHciCluster 命令。 下面的示例在前面的步骤中创建的名为“mycluster”的现有群集中,将控制平面节点缩放为 3。
Set-AksHciCluster -name mycluster -controlPlaneNodeCount 3
删除节点池
如果需要删除节点池,请使用 Remove-AksHciNodePool 命令。 下面的示例在名为“mycluster”的群集中删除名为“windowsnodepool”的节点池 。
Remove-AksHciNodePool -clusterName mycluster -name windowsnodepool
为节点池指定排斥
创建节点池时,可将排斥添加到该节点池。 添加排斥时,该节点池中的所有节点也会获取该排斥。 有关排斥和容许的详细信息,请参阅 Kubernetes 排斥和容许。
设置节点池排斥
若要创建具有排斥的节点池,请使用 New-AksHciNodePool。 指定名称 taintnp,并使用 -taints
参数为排斥指定 sku=gpu:noSchedule
。
New-AksHciNodePool -clusterName mycluster -name taintnp -count 1 -osType linux -taints sku=gpu:NoSchedule
注意
只能在创建节点池期间为节点池设置排斥。
运行以下命令,确保节点池已使用指定排斥成功部署。
Get-AksHciNodePool -clusterName mycluster -name taintnp
输出
Status : {Phase, Details}
ClusterName : mycluster
NodePoolName : taintnp
Version : v1.20.7-kvapkg.1
OsType : Linux
NodeCount : 1
VmSize : Standard_K8S3_v1
Phase : Deployed
Taints : {sku=gpu:NoSchedule}
在上一步中,你在创建节点池时应用了 sku=gpu:NoSchedule 排斥。 以下基本示例 YAML 清单使用容许来允许 Kubernetes 计划程序在该节点池中的节点上运行 NGINX Pod。
创建名为 nginx-toleration.yaml
的文件,并复制以下示例中的信息。
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- image: mcr.microsoft.com/oss/nginx/nginx:1.15.9-alpine
name: mypod
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 1
memory: 2G
tolerations:
- key: "sku"
operator: "Equal"
value: "gpu"
effect: "NoSchedule"
然后,使用以下命令计划 Pod。
kubectl apply -f nginx-toleration.yaml
若要验证 Pod 是否已部署,请运行以下命令:
kubectl describe pod mypod
[...]
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
sku=gpu:NoSchedule
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 32s default-scheduler Successfully assigned default/mypod to moc-lk4iodl7h2y
Normal Pulling 30s kubelet Pulling image "mcr.microsoft.com/oss/nginx/nginx:1.15.9-alpine"
Normal Pulled 26s kubelet Successfully pulled image "mcr.microsoft.com/oss/nginx/nginx:1.15.9-alpine" in 4.529046457s
Normal Created 26s kubelet Created container mypod