云容器引擎 CCE-应用扩缩容优先级策略:配置应用扩缩容优先级策略

时间:2024-04-23 19:45:32

配置应用扩缩容优先级策略

  1. 开启应用扩缩容优先级策略开关并成功安装Volcano插件后,会在集群中创建默认扩缩容优先级策略。

    1. 获取默认Balancer CR资源。
      # kubectl get balancer default-balancer -oyaml
      
      apiVersion: autoscaling.volcano.sh/v1alpha1
      kind: Balancer
      metadata:
        name: default-balancer
      spec:
        balancerPolicyTemplateName: default-balancerpolicytemplate
        targets:
        - namespaceSelector:
            matchExpressions:
              - key: kubernetes.io/metadata.name
                operator: Exists
        weight: 10 
    2. 获取默认BalancerPolicyTemplate CR资源。
      # kubectl get balancerpolicytemplate default-balancerpolicytemplate -oyaml
      
      apiVersion: autoscaling.volcano.sh/v1alpha1
      kind: BalancerPolicyTemplate
      metadata:
        name: default-balancerpolicytemplate
      spec:
        policy:
          policyName: Priority
          priorities:
            priorityGroups:
            - priority: 10
              requirements:
              - key: node.cce.io/billing-mode
                operator: In
                values:
                - post-paid
            - priority: 100
              requirements:
              - key: node.cce.io/billing-mode
                operator: In
                values:
                - pre-paid
            - priority: 1
              requirements:
              - key: kubernetes.io/role
                operator: In
                values:
                - virtual-kubelet
                - bursting

    具体参数含义请参见默认应用扩缩容优先级策略

  2. 部署工作负载,设定实例数为1。

    当前应用的Pod将会优先调度到包周期节点上。

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: balancer-test
      namespace: default
      labels:
        virtual-kubelet.io/burst-to-cci: 'auto'  #如果集群资源不足时,支持将Pod部署到CCI集群
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: balancer-test
      template:
          labels:
            app: balancer-test
        spec:
          containers:
            image: nginx:latest
            imagePullPolicy: IfNotPresent
            name: container-1
            resources:
              limits:
                cpu: 250m
                memory: 512Mi
              requests:
                cpu: 250m
                memory: 512Mi
          schedulerName: volcano

  3. 调整工作负载实例数为5。

    当前应用的Pod将会优先调度到包周期节点上。在包周期节点资源不足情况下,优先调度到按需计费节点上。在按需计费节点资源不足情况下,优先调度到virtual-kubelet节点(弹性至CCI)。

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: balancer-test
      namespace: default
      labels:
        virtual-kubelet.io/burst-to-cci: 'auto'  #如果集群资源不足时,支持将Pod部署到CCI集群
    spec:
      replicas: 5
      selector:
        matchLabels:
          app: balancer-test
      template:
          labels:
            app: balancer-test
        spec:
          containers:
            image: nginx:latest
            imagePullPolicy: IfNotPresent
            name: container-1
            resources:
              limits:
                cpu: 250m
                memory: 512Mi
              requests:
                cpu: 250m
                memory: 512Mi
          schedulerName: volcano

  4. 查看各种类型节点上Pod的分值。

    1. 包周期节点上的Pod。
      apiVersion: v1
      kind: Pod
      metadata:
        annotations:
          autoscaling.volcano.sh/dominated-by-balancer: default-balancer  #当前Pod通过名为default-balancer的Balancer CR资源控制扩缩优先级
          openvessel.io/workload-balancer-score: "100" #当前包周期节点对应的优先级,也代表着Pod的分值
          ...
        nodeName: 192.168.20.100 #包周期节点
    2. 按需计费节点上的Pod。
      apiVersion: v1
      kind: Pod
      metadata:
        annotations:
          autoscaling.volcano.sh/dominated-by-balancer: default-balancer #当前Pod通过名为default-balancer的Balancer CR资源控制扩缩优先级
          openvessel.io/workload-balancer-score "10"  #当前按需计费节点对应的优先级,也代表着Pod的分值
          ...
        nodeName: 192.168.20.196 #按需计费节点
    3. virtual-kubelet节点(弹性至CCI)的Pod。
      apiVersion: v1
      kind: Pod
      metadata:
        annotations:
          autoscaling.volcano.sh/dominated-by-balancer: default-balancer #当前Pod通过名为default-balancer的Balancer CR资源控制扩缩优先级
          openvessel.io/workload-balancer-score: "1"  #当前virtual-kubelet节点对应的优先级,也代表着pod的分值
          ...
        nodeName: virtual-kubelet #virtual-kubelet节点

  5. 逐步进行工作负载的缩容操作,调小实例数。

    virtual-kubelet节点(弹性至CCI)的Pod将优先被删除,其次为按需计费节点上的Pod,最后为包周期节点上的Pod。

support.huaweicloud.com/usermanual-cce/cce_10_0746.html