searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

突破地域限制,多地域Serverless算力调度

2025-06-06 08:26:19
0
0

指定地域调度

在默认情况下,如果我们需要将业的Serverless算力调度到指定的地域,可以在业务应用的定义中添加标签ctyun.cn/specified-region-id来实现。编排如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    esx: nginx-gpu-specified-region
  name: nginx-gpu-deployment-specified-region
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      esx: nginx-gpu-specified-region
  template:
    metadata:
      labels:
        ctyun.cn/esx: "true"
        ctyun.cn/compute-class: gpu
        ctyun.cn/compute-qos: default
        ctyun.cn/gpu-model-series: example-model  # GPU卡型,请按照实际情况替换,例如T4
        ctyun.cn/specified-region-id: <RegionID> # 通过该标签指定地域,若不指定会使用默认地域,// RegionID由集群服务提供
        esx: nginx-gpu-specified-region
    spec: 
      containers:
        - image: 'nginx:stable-alpine'
          imagePullPolicy: IfNotPresent
          name: nginx
          ports:
            - containerPort: 80
              protocol: TCP
          resources:
            limits:
              cpu: 1
              memory: 1Gi
              nvidia.com/gpu: "1"
            requests:
              cpu: 1
              memory: 1Gi
              nvidia.com/gpu: "1"

调度器动态调度

在指定地域调度的示例中,是通过为业务应用设置标签来实现将业务应用调度到指定地域的Serverless算力。然而,这种方式存在一定的限制和缺少灵活性。为了解决该问题,通过调度器ResourcePolicy策略实现动态调度。

策略定义如下:

apiVersion: scheduling.ctyun.cn/v1
kind: Policy
metadata:
  name: multi-vk-gpu-resourcepolicy
  namespace: default
spec:
  selector: # 在selector中标记Pod,表示带有esx=nginx-gpu-resourcepolicy标签的Pod将遵循此调度策略
    esx: nginx-gpu-resourcepolicy
  units:
  # 优先使用该地域的资源,当该地域资源不足时候,自动切换到其他地域
  - resource: bc # resource类型指定业务资源为bc
    replicas: 1
    schedulerNodeSelector: # 支持通过nodeSelector指定虚拟节点地域
      topology.kubernetes.io/region: <RegionID>
      spec: uuid
    podLabels:
      ctyun.cn/specified-region-id: <RegionID>
      ctyun.cn/compute-class: gpu
      ctyun.cn/compute-qos: default
      ctyun.cn/gpu-model-series: example-model  # GPU卡型,请按照实际情况替换
  - resource: bc
    replicas: 2
    nodeSelector: # 支持通过nodeSelector指定虚拟节点地域
      topology.kubernetes.io/region: <RegionID>
      spec: uuid
    podLabels:
      ctyun.cn/specified-region-id: <RegionID>
      ctyun.cn/compute-class: gpu
      ctyun.cn/compute-qos: default
      ctyun.cn/gpu-model-series: example-model  # GPU卡型,请按照实际情况替换

调度成功后,在ResourceBinding最后采用GVR实现动态标签注入。获取资源的标签,如果标签为空,则创建一个新的标签映射,然后添加一个新的标签,并将其设置回unstructured对象中,实现概要如下:

// 将 YAML 解析为 unstructured 对象
var obj unstructured.Unstructured
err = yaml.Unmarshal(yamlFile, &obj)
if err != nil {
    log.Fatalf("Failed to unmarshal YAML: %v", err)
}
 
// 获取 GVR
gvk := obj.GroupVersionKind()
gvr := schema.GroupVersionResource{
    Group:    gvk.Group,
    Version:  gvk.Version,
    Resource: fmt.Sprintf("%ss", gvk.Kind),
}
 
// 动态注入标签
labels := obj.GetLabels()
if labels == nil {
    labels = make(map[string]string)
}
labels["example-label"] = "example-value"
obj.SetLabels(labels)

调度器框架

0条评论
0 / 1000
青衫9527
6文章数
0粉丝数
青衫9527
6 文章 | 0 粉丝
原创

突破地域限制,多地域Serverless算力调度

2025-06-06 08:26:19
0
0

指定地域调度

在默认情况下,如果我们需要将业的Serverless算力调度到指定的地域,可以在业务应用的定义中添加标签ctyun.cn/specified-region-id来实现。编排如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    esx: nginx-gpu-specified-region
  name: nginx-gpu-deployment-specified-region
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      esx: nginx-gpu-specified-region
  template:
    metadata:
      labels:
        ctyun.cn/esx: "true"
        ctyun.cn/compute-class: gpu
        ctyun.cn/compute-qos: default
        ctyun.cn/gpu-model-series: example-model  # GPU卡型,请按照实际情况替换,例如T4
        ctyun.cn/specified-region-id: <RegionID> # 通过该标签指定地域,若不指定会使用默认地域,// RegionID由集群服务提供
        esx: nginx-gpu-specified-region
    spec: 
      containers:
        - image: 'nginx:stable-alpine'
          imagePullPolicy: IfNotPresent
          name: nginx
          ports:
            - containerPort: 80
              protocol: TCP
          resources:
            limits:
              cpu: 1
              memory: 1Gi
              nvidia.com/gpu: "1"
            requests:
              cpu: 1
              memory: 1Gi
              nvidia.com/gpu: "1"

调度器动态调度

在指定地域调度的示例中,是通过为业务应用设置标签来实现将业务应用调度到指定地域的Serverless算力。然而,这种方式存在一定的限制和缺少灵活性。为了解决该问题,通过调度器ResourcePolicy策略实现动态调度。

策略定义如下:

apiVersion: scheduling.ctyun.cn/v1
kind: Policy
metadata:
  name: multi-vk-gpu-resourcepolicy
  namespace: default
spec:
  selector: # 在selector中标记Pod,表示带有esx=nginx-gpu-resourcepolicy标签的Pod将遵循此调度策略
    esx: nginx-gpu-resourcepolicy
  units:
  # 优先使用该地域的资源,当该地域资源不足时候,自动切换到其他地域
  - resource: bc # resource类型指定业务资源为bc
    replicas: 1
    schedulerNodeSelector: # 支持通过nodeSelector指定虚拟节点地域
      topology.kubernetes.io/region: <RegionID>
      spec: uuid
    podLabels:
      ctyun.cn/specified-region-id: <RegionID>
      ctyun.cn/compute-class: gpu
      ctyun.cn/compute-qos: default
      ctyun.cn/gpu-model-series: example-model  # GPU卡型,请按照实际情况替换
  - resource: bc
    replicas: 2
    nodeSelector: # 支持通过nodeSelector指定虚拟节点地域
      topology.kubernetes.io/region: <RegionID>
      spec: uuid
    podLabels:
      ctyun.cn/specified-region-id: <RegionID>
      ctyun.cn/compute-class: gpu
      ctyun.cn/compute-qos: default
      ctyun.cn/gpu-model-series: example-model  # GPU卡型,请按照实际情况替换

调度成功后,在ResourceBinding最后采用GVR实现动态标签注入。获取资源的标签,如果标签为空,则创建一个新的标签映射,然后添加一个新的标签,并将其设置回unstructured对象中,实现概要如下:

// 将 YAML 解析为 unstructured 对象
var obj unstructured.Unstructured
err = yaml.Unmarshal(yamlFile, &obj)
if err != nil {
    log.Fatalf("Failed to unmarshal YAML: %v", err)
}
 
// 获取 GVR
gvk := obj.GroupVersionKind()
gvr := schema.GroupVersionResource{
    Group:    gvk.Group,
    Version:  gvk.Version,
    Resource: fmt.Sprintf("%ss", gvk.Kind),
}
 
// 动态注入标签
labels := obj.GetLabels()
if labels == nil {
    labels = make(map[string]string)
}
labels["example-label"] = "example-value"
obj.SetLabels(labels)

调度器框架

文章来自个人专栏
文章 | 订阅
0条评论
0 / 1000
请输入你的评论
0
0