Colocation Profile

Motivation

如果现有集群中的工作负载想要通过 Koordinator 进行混合部署,则需要修改现有的 Controller/Operator 以支持 Koordinator 定义的 QoS Class、优先级和资源模型等协议。为了降低 Koordinator 混部系统的使用门槛,让大家可以简单快速的使用混部技术获得收益,因此 Koordinator 提供了一个 ClusterColocationProfile CRD 和 对应的 Webhook 修改和验证新创建的 Pod,注入 ClusterColocationProfile 中描述的字段。

构架

image

Feature Gates

ClusterColocationProfile mutating/validating 功能默认是打开的,如果想要关闭,请设置 Feature Gates:

1. $ helm install koordinator https://... --set featureGates="PodMutatingWebhook=false\,PodValidatingWebhook=false"

规格定义

如果您对 Kubernetes 资源不熟悉,请参考页面 了解 Kubernetes 对象。

  • namespaceSelector: 如果命名空间与选择器匹配,则决定是否改变/验证 Pod。 LabelSelector 默认为空,它将匹配所有 Namespace。
  • selector: 如果 Pod 与选择器匹配,则决定是否改变/验证 Pod。 默认为空的 LabelSelector,它将匹配所有 Pod。
  • qosClass (required): 描述了 Pod 的 Koordinator QoSClass。该值以标签 koordinator.sh/qosClass 的形式更新到 Pod 中。对应的选项为 LSE、LSR、LS、BE 和 SYSTEM。 有关更多信息,请查看页面此处。
  • priorityClassName (required): 指定要写入到 Pod.Spec.PriorityClassName 中的 Kubenretes PriorityClass. 选项为 koord-prod、koord-mid、koord-batch 和 koord-free。有关更多信息,请查看 此处。
  • koordinatorPriority: Koordinator 还提供了 Pod 级别的子优先级 sub-priority。 优先级值将作为标签 koordinator.sh/priority 更新到 Pod。 各个 Koordinator 组件通过 KoordinatorPriority 和 PriorityClassName 中的优先级值来确定 Koordinator 中 Pod 的优先级,值越高,优先级越高。
  • labels: 描述需要注入到 Pod.Labels 的 k/v 键值对。
  • annotations: 描述了需要注入到 Pod.Annotations 的 k/v 键值对。
  • schedulerName: 如果指定,则 Pod 将由指定的调度器调度。
  • patch: 表示用户想要注入 Pod 的 Pod 模板补丁。

例子

创建 ClusterColocationProfile

下面的 profile.yaml 文件描述了对所有含有标签 koordinator.sh/enable-colocation=true 的 Namespace 下的所有含有标签 koordinator.sh/enable-colocation=true 的 Pod 进行修改,注入 Koordinator QoSClass、Koordinator Priority 等。

1. apiVersion: config.koordinator.sh/v1alpha1
2. kind: ClusterColocationProfile
3. metadata:
4. name: colocation-profile-example
5. spec:
6. namespaceSelector:
7. matchLabels:
8. koordinator.sh/enable-colocation: "true"
9. selector:
10. matchLabels:
11. koordinator.sh/enable-colocation: "true"
12. qosClass: BE
13. priorityClassName: koord-batch
14. koordinatorPriority: 1000
15. schedulerName: koord-scheduler
16. labels:
17. koordinator.sh/mutated: "true"
18. annotations:
19. koordinator.sh/intercepted: "true"
20. patch:
21. spec:
22. terminationGracePeriodSeconds: 30

基于 YAML 文件创建 ClusterColocationProfile:

1. $ kubectl apply -f profile.yaml

验证 ClusterColocationProfile 是否生效

1. apiVersion: v1
2. kind: Pod
3. metadata:
4. labels:
5. koordinator.sh/enable-colocation: "true"
6. name: test-pod
7. spec:
8. containers:
9. - name: app
10. image: nginx:1.15.1
11. resources:
12. limits:
13. cpu: "1"
14. memory: "3456Mi"
15. requests:
16. cpu: "1"
17. memory: "3456Mi"

创建这个 Pod,现在你会发现该 Pod 被注入了 Koordinator QoSClass、Koordinator Priority 等。

1. $ kubectl get pod test-pod -o yaml
2. apiVersion: v1
3. kind: Pod
4. metadata:
5. annotations:
6. koordinator.sh/intercepted: true
7. labels:
8. koordinator.sh/qosClass: BE
9. koordinator.sh/priority: 1000
10. koordinator.sh/mutated: true
11. ...
12. spec:
13. terminationGracePeriodSeconds: 30
14. priority: 5000
15. priorityClassName: koord-batch
16. schedulerName: koord-scheduler
17. containers:
18. - name: app
19. image: nginx:1.15.1
20. resources:
21. limits:
22. kubernetes.io/batch-cpu: "1000"
23. kubernetes.io/batch-memory: 3456Mi
24. requests:
25. kubernetes.io/batch-cpu: "1000"
26. kubernetes.io/batch-memory: 3456Mi