调度Pod到Windows虚拟节点

更新时间:
复制为 MD 格式

ECI已支持操作系统为Windows的实例。如果您的容器需要运行在Windows环境,您可以在集群中添加Windows虚拟节点,并将Pod调度到该虚拟节点上,即可创建出操作系统为WindowsECI Pod(即ECI实例)来运行容器。

前提条件

使用限制

  • 创建操作系统为WindowsECI实例时,实例规格不得低于2 vCPU、4 GiB内存。

  • Windows容器镜像的版本号需要满足10.0.20348.*,即Windows Server 2022。

  • 不支持以下特性:

    • 操作系统不支持本地盘。

    • 暂不支持GPU算力。

    • 不支持Windows HostProcess 容器。

    更多不支持的特性,请参见Kubernetes 中的 Windows 容器

添加Windows虚拟节点

通过以下步骤修改eci-profile,在集群中添加Windows虚拟节点。

控制台

  1. ACK集群列表页面,单击目标集群名称,在集群详情页左侧导航栏,选择配置管理 > 配置项

  2. 选择kube-system命名空间,单击eci-profile配置项右侧操作列的编辑

  3. 单击添加,在名称中分别填写enableWindowsAmd64Nodetrue,然后单击确定

  4. 在左侧导航栏中选择节点管理 > 节点池,验证已新增Windows虚拟节点。

kubectl

  1. 获取集群kubeconfig并通过kubectl工具连接集群

  2. 修改集群 ConfigMap 中的eci-profile配置项。

    kubectl edit -n kube-system cm/eci-profile
  3. data中新增enableWindowsAmd64Node: "true"配置。

    data:
      ......
      enableWindowsAmd64Node: "true"   #启用Windows节点
      ......
  4. 验证已新增Windows虚拟节点。

    kubectl get nodes -l kubernetes.io/os=windows

    预期输出:

    NAME                                          STATUS   ROLES   AGE   VERSION
    virtual-kubelet-cn-hangzhou-i-windows-amd64   Ready    agent   23m   v1.34.3-aliyun.1
    virtual-kubelet-cn-hangzhou-j-windows-amd64   Ready    agent   23m   v1.34.3-aliyun.1
    virtual-kubelet-cn-hangzhou-k-windows-amd64   Ready    agent   23m   v1.34.3-aliyun.1

Windows工作负载使用示例

由于Windows虚拟节点带有kubernetes.io/os: windows的标签,创建Windows工作负载时需使用nodeSelector来指定Windows虚拟节点。

Windows工作负载中使用Secret

  1. 创建一个Windows工作负载,并将Secret挂载到C盘的secrets目录。

    使用以下内容创建windows-deploy-secret-example.yaml文件,然后执行kubectl apply -f windows-deploy-secret-example.yaml创建资源。
    apiVersion: v1
    kind: Secret
    metadata:
      name: windows-test-secret
    type: Opaque
    stringData:
      username: testuser
      password: testpass123
      secret.txt: "This is a secret file for Windows Pod"
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: windows-deployment-secret-example
      labels:
        app: windows-secret-app
    spec:
      replicas: 1 # 示例副本数设置为 1
      selector:
        matchLabels:
          app: windows-secret-app
      template:
        metadata:
          labels:
            app: windows-secret-app
            alibabacloud.com/acs: "true"
        spec:
          nodeSelector:
            kubernetes.io/os: windows
          containers:
          - name: test
            image: registry-cn-hangzhou.ack.aliyuncs.com/test/nanoserver:ltsc2022
            command: ["ping", "-t", "localhost"]
            resources:
              requests:
                cpu: "4"         
                memory: "8Gi"     
              limits:
                cpu: "4"         
                memory: "8Gi"
            volumeMounts:
            - name: secret-volume
              mountPath: C:\secrets
              readOnly: true
          volumes:
          - name: secret-volume
            secret:
              secretName: windows-test-secret
  2. 验证工作负载正常运行,并查看Secret内容。

    1. 进入容器CMD命令行。

      kubectl exec -it deployment/windows-deployment-secret-example -- cmd
    2. 在命令行中验证Secret内容。

      # 进入Secret挂载目录 
      C:\>cd secrets
      
      # 查看Secret内容 
      C:\secrets>type secret.txt
      This is a secret file for Windows Pod

Windows工作负载挂载EIP

  1. 安装ack-extend-network-controller组件,详细操作请参见通过配置注解为Pod挂载EIP

  2. 使用network.alibabacloud.com/pod-with-eip: "true"注解创建Windows工作负载。

    使用以下内容创建windows-deploy-eip-example.yaml文件,然后执行kubectl apply -f windows-deploy-eip-example.yaml创建资源。
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: windows-deployment-eip-example
      labels:
        app: windows-eip-app
    spec:
      replicas: 1 # 示例副本数设置为 1
      selector:
        matchLabels:
          app: windows-eip-app
      template:
        metadata:
          labels:
            app: windows-eip-app
            alibabacloud.com/acs: "true"
          annotations:
            network.alibabacloud.com/pod-with-eip: "true"
        spec:
          nodeSelector:
            kubernetes.io/os: windows
          containers:
          - name: test
            image: registry-cn-hangzhou.ack.aliyuncs.com/test/nanoserver:ltsc2022
            command: ["ping", "-t", "localhost"]
            resources:
              requests:
                cpu: "4"
                memory: "8Gi"
              limits:
                cpu: "4"
                memory: "8Gi"
  3. 获取Pod EIP。

    kubectl get pod $(kubectl get pods -l app=windows-eip-app -o jsonpath='{.items[0].metadata.name}') -o jsonpath="{.metadata.annotations['network\.alibabacloud\.com/allocated-eipAddress']}"
    预期输出的EIP请以实际为准。