部署 Windows 节点

    • Windows 容器支持 Pod(isolation=process)
    • 基于 Virtual Filtering Platform (VFP) Hyper-v Switch Extension 的内核负载均衡
    • 基于 Container Runtime Interface (CRI) 管理 Windows 容器
    • 支持 kubeadm 命令将 Windows 节点加入到已有集群中
    • 推荐使用 Windows Server Version 1709+ 和 Docker Version 17.06+

    可以从 <https://github.com/kubernetes/kubernetes/releases 下载已发布的用于 Windows 服务器的二进制文件,如

    或者从 Kubernetes 源码编译

    1. cd $GOPATH/src/k8s.io/kubernetes
    2. # Build the kubelet
    3. KUBE_BUILD_PLATFORMS=windows/amd64 make WHAT=cmd/kubelet
    4. # Build the kube-proxy
    5. KUBE_BUILD_PLATFORMS=windows/amd64 make WHAT=cmd/kube-proxy
    6. # You will find the output binaries under the folder _output/local/bin/windows/

    Windows Server 中支持以下几种网络插件(注意 Windows 节点上的网络插件要与 Linux 节点相同)

    1. 等 L3 路由网络插件,路由配置在 TOR 交换机、路由器或者云服务中
    2. Host Gateway 网络插件,跟上面类似但将 IP 路由配置到每台主机上面
    3. Open vSwitch (OVS) & Open Virtual Network (OVN) with Overlay
    4. Flannel v0.10.0+
    5. Calico v3.0.1+
    6. 未来还会支持

    wincni 网络插件配置示例

    1. {
    2. "cniVersion": "0.2.0",
    3. "name": "l2bridge",
    4. "type": "wincni.exe",
    5. "master": "Ethernet",
    6. "ipam": {
    7. "environment": "azure",
    8. "subnet": "10.10.187.64/26",
    9. "routes": [{
    10. "GW": "10.10.187.66"
    11. }]
    12. },
    13. "dns": {
    14. "Nameservers": [
    15. "11.0.0.10"
    16. ]
    17. },
    18. "AdditionalArgs": [{
    19. "Name": "EndpointPolicy",
    20. "Value": {
    21. "Type": "OutBoundNAT",
    22. "ExceptionList": [
    23. "11.0.0.0/8",
    24. "10.10.0.0/16",
    25. "10.127.132.128/25"
    26. ]
    27. }
    28. },
    29. {
    30. "Name": "EndpointPolicy",
    31. "Value": {
    32. "Type": "ROUTE",
    33. "DestinationPrefix": "11.0.0.0/8",
    34. "NeedEncap": true
    35. },
    36. {
    37. "Name": "EndpointPolicy",
    38. "Value": {
    39. "Type": "ROUTE",
    40. "DestinationPrefix": "10.127.132.213/32",
    41. "NeedEncap": true
    42. }
    43. }
    44. ]
    45. }

    OVS 网络拓扑

    kubeadm

    如果 Master 是通过 kubeadm 来部署的,那 Windows 节点也可以使用 kubeadm 来部署:

    1. kubeadm.exe join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash sha256:<hash>

    在 Azure 上面推荐使用 acs-engine 自动部署 Master 和 Windows 节点。

    手动部署

    1. 在 Windows Server 中 安装 Docker

    2. 根据前面的下载部分下载或者编译 kubelet.exe 和 kube-proxy.exe

    3. 从 Master 节点上面拷贝 Node spec file (kube config)

    4. 创建 HNS 网络,配置 CNI 网络插件

      1. wget https://github.com/Microsoft/SDN/archive/master.zip -o master.zip
      2. Expand-Archive master.zip -DestinationPath master
      3. mv master/SDN-master/Kubernetes/windows/* C:/k/
      4. rm -recurse -force master,master.zip
    5. ```sh

    ./start-kubelet.ps1 -ClusterCidr 192.168.0.0/16
    ./start-kubeproxy.ps1

    1. 6. 如果使用 Host-Gateway 网络插件,还需要使用 [AddRoutes.ps1](https://github.com/Microsoft/SDN/blob/master/Kubernetes/windows/AddRoutes.ps1) 添加静态路由
    2. 详细的操作步骤可以参考 [这里](https://github.com/MicrosoftDocs/Virtualization-Documentation/blob/live/virtualization/windowscontainers/kubernetes/getting-started-kubernetes-windows.md)。
    3. ## 运行 Windows 容器
    4. 使用 NodeSelector `beta.kubernetes.io/os: windows` 将容器调度到 Windows 节点上,比如
    5. ```yaml
    6. apiVersion: extensions/v1beta1
    7. kind: Deployment
    8. metadata:
    9. name: iis
    10. spec:
    11. replicas: 1
    12. template:
    13. metadata:
    14. labels:
    15. app: iis
    16. spec:
    17. nodeSelector:
    18. beta.kubernetes.io/os: windows
    19. containers:
    20. - name: iis
    21. image: microsoft/iis
    22. resources:
    23. limits:
    24. memory: "128Mi"
    25. cpu: 2
    26. ports:
    27. - containerPort: 80
    28. ---
    29. apiVersion: v1
    30. kind: Service
    31. metadata:
    32. labels:
    33. app: iis
    34. name: iis
    35. namespace: default
    36. spec:
    37. ports:
    38. - port: 80
    39. protocol: TCP
    40. targetPort: 80
    41. selector:
    42. app: iis
    43. type: NodePort

    运行 DaemonSet

    1. kind: DaemonSet
    2. metadata:
    3. name: my-DaemonSet
    4. labels:
    5. app: foo
    6. spec:
    7. template:
    8. labels:
    9. app: foo
    10. spec:
    11. containers:
    12. - name: foo
    13. image: microsoft/windowsservercore:1709
    14. nodeSelector:
    15. beta.kubernetes.io/os: windows

    Secrets 和 ConfigMaps 只能以环境变量的方式使用

    Windows 容器暂时只支持 local、emptyDir、hostPath、AzureDisk、AzureFile 以及 flexvolume。注意 Volume 的路径格式需要为 mountPath: "C:\\etc\\foo" 或者 mountPath: "C:/etc/foo"

    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: hostpath-pod
    5. spec:
    6. containers:
    7. - name: hostpath-nano
    8. image: microsoft/nanoserver:1709
    9. stdin: true
    10. tty: true
    11. volumeMounts:
    12. - name: blah
    13. mountPath: "C:\\etc\\foo"
    14. readOnly: true
    15. nodeSelector:
    16. beta.kubernetes.io/os: windows
    17. volumes:
    18. - name: blah
    19. hostPath:
    20. path: "C:\\AzureData"
    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: empty-dir-pod
    5. spec:
    6. containers:
    7. - image: microsoft/nanoserver:1709
    8. name: empty-dir-nano
    9. stdin: true
    10. tty: true
    11. volumeMounts:
    12. - mountPath: /cache
    13. name: cache-volume
    14. - mountPath: C:/scratch
    15. name: scratch-volume
    16. volumes:
    17. - name: cache-volume
    18. emptyDir: {}
    19. - name: scratch-volume
    20. emptyDir: {}
    21. nodeSelector:
    22. beta.kubernetes.io/os: windows

    镜像版本匹配问题

    Windows Server version 1709 中必须使用带有 1709 标签的镜像,如

    1. microsoft/aspnet:4.7.1-windowsservercore-1709
    2. microsoft/windowsservercore:1709
    3. microsoft/iis:windowsservercore-1709

    而在 Windows Server 2016 上需要使用带有 ltsc2016 标签的镜像,如 microsoft/windowsservercore:ltsc2016

    v1.9 版本已知问题

    • 仅 Windows Server 1709 或更新的版本才支持在 Pod 内运行多个容器(仅支持 Process 隔离)
    • 暂不支持以 Volume 挂载的方式使用 Secrets 和 ConfigMaps
    • 暂不支持 StatefulSet
    • 暂不支持 Windows Server Container Pods 的自动扩展(Horizontal Pod Autoscaling)
    • 暂不支持 Hyper-V 隔离方式
    • Windows 容器的 OS 版本需要与 Host OS 版本匹配,否则容器无法启动
    • 使用 L3 或者 Host GW 网络时,无法从 Windows Node 中直接访问 Kubernetes Services(使用 OVS/OVN 时没有这个问题)
    • 在 VMWare Fusion 的 Window Server 中 kubelet.exe 可能会无法启动(已在 #57124 中修复)
    • 暂不支持 Weave 网络插件