本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
运行异构工作负载
Kubernetes 支持异构集群,您可以在同一个集群中混合使用 Linux 和 Windows 节点。在该集群中,你可以混合运行在 Linux 上的 Pod 和在 Windows 上运行的 Pod。你甚至可以在同一个集群中运行多个版本的 Windows。但是,在做出此决定时,需要考虑几个因素(如下所述)。
将 POD 分配给节点最佳实践
为了将 Linux 和 Windows 工作负载保留在各自的 OS-specific 节点上,您需要使用节点选择器和 taints/tolerations的某种组合。在异构环境中调度工作负载的主要目标是避免破坏现有 Linux 工作负载的兼容性。
确保 OS-specific 工作负载落在相应的容器主机上
用户可以确保使用节点选择器将 Windows 容器调度到相应的主机上。当今所有 Kubernetes 节点都有以下默认标签:
kubernetes.io/os = [windows|linux] kubernetes.io/arch = [amd64|arm64|...]
如果 Pod 规格不包含类似的节点选择器,则可以将该 Pod 调度到任何主机"kubernetes.io/os": windows,无论是 Windows 还是 Linux 上。这可能是有问题的,因为Windows容器只能在Windows上运行,而Linux容器只能在Linux上运行。
在企业环境中,有大量预先存在的 Linux 容器部署以及 Helm Charts 等现成配置生态系统的情况并不少见。在这种情况下,你可能会对部署的 NodeSelector 进行更改犹豫不决。另一种选择是使用 Taints。
例如:--register-with-taints='os=windows:NoSchedule'
如果你使用的是 EKS,eksctl 提供了通过 ClusterConfig 应用污点的方法:
NodeGroups: - name: windows-ng amiFamily: WindowsServer2022FullContainer ... labels: nodeclass: windows2022 taints: os: "windows:NoSchedule"
向所有 Windows 节点添加污点,除非这些节点容忍污点,否则调度器不会在这些节点上调度 pod。Pod 清单示例:
nodeSelector: kubernetes.io/os: windows tolerations: - key: "os" operator: "Equal" value: "windows" effect: "NoSchedule"
在同一个集群中处理多个 Windows 版本
每个 Pod 使用的 Windows 容器基础镜像必须与该节点的内核编译版本相匹配。如果你想在同一个集群中使用多个 Windows Server 版本,那么你应该设置额外的节点标签、节点选择器或利用一个名为 windows-build 的标签。
Kubernetes 1.17 自动添加了一个新标签 node.kubernetes。io/windows-build 可简化对同一个集群中多个 Windows 版本的管理。如果你运行的是旧版本,则建议将此标签手动添加到 Windows 节点。
此标签反映了需要匹配才能兼容的 Windows 主要、次要和内部版本号。以下是当今每个 Windows 服务器版本使用的值。
值得注意的是,Windows服务器正在转向 Long-Term 服务渠道(LTSC)作为主要发布渠道。Windows 服务器 Semi-Annual 频道 (SAC) 已于 2022 年 8 月 9 日停用。将来不会有Windows服务器的SAC版本。
| 产品名称 | 版本号 |
|---|---|
|
服务器已满 2022 LTSC |
10.0.20348 |
|
服务器核心 2019 LTSC |
10.0.17763 |
可以通过以下命令检查操作系统构建版本:
kubectl get nodes -o wide
KERNEL-VERSION 输出与 Windows 操作系统构建版本相匹配。
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME ip-10-10-2-235.ec2.internal Ready <none> 23m v1.24.7-eks-fb459a0 10.10.2.235 3.236.30.157 Windows Server 2022 Datacenter 10.0.20348.1607 containerd://1.6.6 ip-10-10-31-27.ec2.internal Ready <none> 23m v1.24.7-eks-fb459a0 10.10.31.27 44.204.218.24 Windows Server 2019 Datacenter 10.0.17763.4131 containerd://1.6.6 ip-10-10-7-54.ec2.internal Ready <none> 31m v1.24.11-eks-a59e1f0 10.10.7.54 3.227.8.172 Amazon Linux 2 5.10.173-154.642.amzn2.x86_64 containerd://1.6.19
以下示例将额外的节点选择器应用到容器清单中,以便在运行不同的 Windows 节点组操作系统 Windows-build 版本时匹配正确的版本。
nodeSelector: kubernetes.io/os: windows node.kubernetes.io/windows-build: '10.0.20348' tolerations: - key: "os" operator: "Equal" value: "windows" effect: "NoSchedule"
在 Pod 清单中使用简 NodeSelector 化和容忍 RuntimeClass
您还可以利用 RuntimeClass 来简化使用污点和容忍度的过程。这可以通过创建一个用于封装这些污点和容忍度的 RuntimeClass 对象来实现。
RuntimeClass 通过运行以下清单创建:
apiVersion: node.k8s.io/v1beta1 kind: RuntimeClass metadata: name: windows-2022 handler: 'docker' scheduling: nodeSelector: kubernetes.io/os: 'windows' kubernetes.io/arch: 'amd64' node.kubernetes.io/windows-build: '10.0.20348' tolerations: - effect: NoSchedule key: os operator: Equal value: "windows"
创建 Runtimeclass 后,将其作为 Pod 清单上的规格进行分配:
apiVersion: apps/v1 kind: Deployment metadata: name: iis-2022 labels: app: iis-2022 spec: replicas: 1 template: metadata: name: iis-2022 labels: app: iis-2022 spec: runtimeClassName: windows-2022 containers: - name: iis
托管节点组支持
为了帮助客户以更简化的方式运行其Windows应用程序,AWS于2022年12月15 日启动了对Windows容器的亚马逊
以下 AMI 系列支持托管节点组 (MNG)。
| AMI 家族 |
|---|
|
Windows_Core_2019_x86_64 |
|
Windows_full_2019_x86_64 |
|
Windows_Core_2022_x86_64 |
|
Windows_full_2022_x86_64 |
其他文档
AWS 官方文档:https://docs.aws.amazon.com/eks/latest/userguide/windows-support.html
要更好地了解 Pod 网络 (CNI) 的工作原理,请查看以下链接:https://docs.aws.amazon.com/eks/latest/userguide/pod-networking.html
关于在 EKS 上部署适用于 Windows 的托管节点组的 AWS 博客:https://aws.amazon.com/blogs/containers/deploying-amazon-eks-windows-managed-node-groups/