在ACS集群中创建Windows工作负载

更新时间:
复制为 MD 格式

本文介绍如何在ACS集群中添加Windows虚拟节点,并将ACS Pod调度到该虚拟节点,从而运行Windows环境中部署的业务。

适用范围

  • 提交工单申请使用本功能。

  • 创建操作系统为WindowsACS工作负载时,PodvCPU和内存必须大于等于2 vCPU 和 4 GiB 内存。

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

  • 不支持以下特性:

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

    • 暂不支持GPU算力。

    • 不支持Windows HostProcess 容器。

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

添加Windows虚拟节点

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

控制台

  1. 登录容器计算服务控制台,在左侧导航栏选择集群列表

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

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

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

  5. 在左侧导航栏中选择虚拟节点,验证已新增Windows虚拟节点。

kubectl

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

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

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

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

    kubectl get node

    预期输出:

    NAME                                          STATUS   ROLES   AGE     VERSION
    virtual-kubelet-cn-hangzhou-i                 Ready    agent   5h47m   v1.32.7-aliyun.1
    virtual-kubelet-cn-hangzhou-i-windows-amd64   Ready    agent   4h26m   v1.32.7-aliyun.1
    virtual-kubelet-cn-hangzhou-j                 Ready    agent   5h47m   v1.32.7-aliyun.1
    virtual-kubelet-cn-hangzhou-j-windows-amd64   Ready    agent   4h26m   v1.32.7-aliyun.1
    virtual-kubelet-cn-hangzhou-k                 Ready    agent   5h47m   v1.32.7-aliyun.1
    virtual-kubelet-cn-hangzhou-k-windows-amd64   Ready    agent   4h26m   v1.32.7-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请以实际为准。