在 AIStudio 镜像中心使用 Dockerfile 自助构建最新版 vLLM 镜像在 AIStudio 镜像中心使用 Dockerfile 自助构建最新版 vLLM 镜像 ,无需访问 DockerHub立即构建
Skip to content

使用集群

本文概述在 AI 容器服务集群中的常见操作与高级能力,帮助您快速验证集群可用性并部署工作负载。

基本使用

本节包含连通性检查、命名空间查看与示例工作负载部署等入门步骤。

检查虚拟集群中的节点

shell
kubectl get nodes

由于控制平面由 AI 容器服务平台维护,因此您只会看到 Worker 节点,输出的数量应与您创建集群时添加的节点数量一致。

shell
% kubectl get nodes
NAME     STATUS   ROLES    AGE   VERSION
vnode1   Ready    <none>   8d    v1.26.15
vnode3   Ready    <none>   8d    v1.26.15

检查集群中的命名空间

shell
kubectl get namespaces

首次使用时,您将看到以下命名空间(假设已开启集群监控):

shell
% kubectl get namespaces
NAME              STATUS   AGE
default           Active   8d    # 系统默认命名空间,建议创建专用命名空间而不是使用默认空间
kube-node-lease   Active   8d    # 系统命名空间,存储节点心跳数据,请勿修改
kube-public       Active   8d    # 系统命名空间,存储公开访问数据,请勿修改
kube-system       Active   8d    # 系统命名空间,运行核心系统组件,请勿修改
monitoring        Active   8d    # 监控相关命名空间,谨慎操作

在虚拟集群中部署资源

  1. 创建命名空间和 NGINX 部署:

    shell
    kubectl create namespace demo-nginx
    kubectl create deployment ngnix-deployment -n demo-nginx --image=m.daocloud.io/docker.io/library/nginx:latest -r 2
  2. 检查 Pod:

    shell
    kubectl get pods -n demo-nginx

    正常输出:

    shell
    % kubectl get pods -n demo-nginx
    NAME                               READY   STATUS    RESTARTS   AGE
    ngnix-deployment-bdf955b54-vf4ld   1/1     Running   0          15s
    ngnix-deployment-bdf955b54-zj28n   1/1     Running   0          15s

重要

如需在 Pod 中获取节点相关信息(如 NODE_NAMEHOSTNAME),请使用平台特定的注解方式,详见集群限制说明。这在 DaemonSet、StatefulSet 等场景中尤为重要。

查看集群中的 GPU 资源

AI 容器服务集群会自动检测节点上的 GPU,并向 API Server 汇报可用资源(如 nvidia.com/gpu=8)。

shell
# 查看节点 GPU 资源
% kubectl get nodes -o jsonpath="{range .items[*]}{.metadata.name}{': '}{.status.allocatable.nvidia\.com/gpu}{'\n'}{end}"
re-dav3kminmvhiyb7a: 8

当 Pod 请求 nvidia.com/gpu 时,设备插件会自动将 GPU 设备(如 /dev/nvidia*)挂载到容器中,并设置必要权限,并不需要开启特权模式。

高级用法

本节介绍对外暴露服务与持久化存储等能力的典型配置。

配置 Nginx Ingress 控制器

平台默认提供 nginx ingressClass,支持创建路由规则,域名绑定和路径转发。

yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: qwen-1-5
spec:
  ingressClassName: nginx
  rules:
  - host: qwen-1-5.example.org
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: qwen-1-5
            port:
              number: 80

使用 Longhorn 供应持久化存储

AI 容器服务集群默认仅提供 LongHorn 存储系统的 StorageClass。不支持租户自助管理 storageclass/ingressclass/pv/csidriver/csinode 等资源。

  • 创建 PVC 时,必须指定为 storageClassName: longhorn
  • PVC 的 accessModes 必须配置为 ReadWriteOnce
  • 单集群 PVC 用量上限为 100GiB。如开启集群监控,需占用 52 GiB。剩余 PVC 可用容量为 48 GiB。
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: demo-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: longhorn

通过 hostPath 使用共享高性能存储

当您在创建集群时已为共享高性能存储选择了文件系统、存储卷与挂载权限,平台会在节点上挂载对应的共享存储根路径(例如 /public)。业务 Pod 可通过 hostPath 将该挂载点或其子目录挂载到容器内,实现读写共享数据。

注意

  • 请仅挂载平台提供的共享存储挂载点或其子目录,避免指向节点系统目录。
  • 权限以创建集群时选择的“挂载权限”为准;若选择只读,则在 Pod 中也只能以只读方式访问。

以下是直接在 Pod 中使用 hostPath 的示例(只读方式)

hostPath.path 替换为平台显示的共享存储挂载点或其子目录。例如平台挂载点为 /public,可挂载 /public/projects

yaml
# 将主机上的 /public/projects 只读挂载到容器内的 /data/projects
apiVersion: v1
kind: Pod
metadata:
  name: hostpath-example-linux
spec:
  os: { name: linux }
  nodeSelector:
    kubernetes.io/os: linux
  containers:
  - name: example-container
    image: registry.k8s.io/test-webserver
    volumeMounts:
    - mountPath: /data/projects
      name: example-volume
      readOnly: true
  volumes:
  - name: example-volume
    hostPath:
  path: /public/projects     # 共享存储的子目录
      type: Directory            # 该路径需已存在;如需自动创建可用 DirectoryOrCreate

也可开启读写并在目录不存在时自动创建,将 type 设为 DirectoryOrCreate,如下所示:

yaml
# 读写示例:自动创建 /public/workspace 并挂载到容器 /data/workspace
apiVersion: v1
kind: Pod
metadata:
  name: hostpath-rw-example
spec:
  os: { name: linux }
  nodeSelector:
    kubernetes.io/os: linux
  containers:
  - name: app
    image: busybox:1.36
    command: ["sh", "-c", "echo hello > /data/workspace/hello.txt && sleep 3600"]
    volumeMounts:
    - mountPath: /data/workspace
      name: workspace
      readOnly: false
  volumes:
  - name: workspace
    hostPath:
      path: /public/workspace      # 必须是共享存储挂载点 /public 的子目录
      type: DirectoryOrCreate      # 目录不存在时自动在主机上创建