Configure GPU resources and enable GPU sharing for Knative

更新时间:
复制 MD 格式

Deploy GPU workloads such as AI inference and HPC on Knative with optional GPU sharing across pods.

Prerequisites

Configure GPU resources

Add the k8s.aliyun.com/eci-use-specs annotation to spec.template.metadata.annotations to specify a GPU-accelerated Elastic Compute Service (ECS) instance type. Add the nvidia.com/gpu field to spec.containers.resources.limits to set the GPU count. If you omit nvidia.com/gpu, the pod reports errors after it starts.

Example Knative Service with one GPU:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
spec:
  template:
    metadata:
      labels:
        app: helloworld-go
      annotations:
        k8s.aliyun.com/eci-use-specs: ecs.gn5i-c4g1.xlarge  # GPU-accelerated ECS instance type
    spec:
      containers:
        - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
          ports:
          - containerPort: 8080
          resources:
            limits:
              nvidia.com/gpu: '1'    # Number of GPUs required. Required field.

Supported GPU instance families

Instance family GPU model Example instance type
gn7i NVIDIA A10 ecs.gn7i-c8g1.2xlarge
gn7 ecs.gn7-c12g1.3xlarge
gn6v NVIDIA V100 ecs.gn6v-c8g1.2xlarge
gn6e NVIDIA V100 ecs.gn6e-c12g1.3xlarge
gn6i NVIDIA T4 ecs.gn6i-c4g1.xlarge

GPU virtualized instance family vgn6i-vws (NVIDIA T4), for example: ecs.vgn6i-m4-vws.xlarge, ecs.vgn6i-m8-vws.2xlarge.

gn5i NVIDIA P4 ecs.gn5i-c2g1.large
gn5 NVIDIA P100 ecs.gn5-c4g1.xlarge
Supported GPU driver: NVIDIA 460.73.01. CUDA Toolkit: 11.2. The gn5 family includes local disks. To mount local disks to ECIs, see Create an elastic container instance that has local disks attached. For available instance types by region, see ECS instance types available for each region and Overview of instance families.

Enable GPU sharing

GPU sharing lets multiple pods share a physical GPU, reducing costs when workloads don't need dedicated GPU access.

To enable GPU sharing:

  1. Enable GPU sharing for nodes.

  2. Add the aliyun.com/gpu-mem field to spec.containers.resources.limits in your Knative Service to set the GPU memory size:

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: helloworld-go
      namespace: default
    spec:
      template:
        metadata:
          annotations:
            autoscaling.knative.dev/maxScale: "100"
            autoscaling.knative.dev/minScale: "0"
        spec:
          containerConcurrency: 1
          containers:
          - image: registry-vpc.cn-hangzhou.aliyuncs.com/hz-suoxing-test/test:helloworld-go
            name: user-container
            ports:
            - containerPort: 6666
              name: http1
              protocol: TCP
            resources:
              limits:
                aliyun.com/gpu-mem: "3"    # Specify the GPU memory size.

Next steps