华为云UCS-使用多集群负载伸缩扩缩工作负载:创建工作负载

时间:2025-02-12 15:02:13

创建工作负载

  1. 使用构建的hpa-example镜像创建无状态工作负载,Pod数为1。镜像地址与上传到的SWR仓库有关,需要替换为实际取值。

    kind: DeploymentapiVersion: apps/v1metadata:  name: hpa-examplespec:  replicas: 1  selector:    matchLabels:      app: hpa-example  template:    metadata:      labels:        app: hpa-example    spec:      containers:      - name: container-1        image: 'hpa-example:latest'   # 替换为您上传到SWR的镜像地址        resources:          limits:                      # limits与requests建议取值保持一致,避免扩缩容过程中出现震荡            cpu: 500m            memory: 200Mi          requests:                                cpu: 500m            memory: 200Mi      imagePullSecrets:      - name: default-secret

  2. 创建一个端口号为80的服务。

    kind: ServiceapiVersion: v1metadata:  name: hpa-examplespec:  ports:    - name: cce-service-0      protocol: TCP      port: 80      targetPort: 80      nodePort: 31144  selector:    app: hpa-example  type: NodePort

  3. 为工作负载和服务创建一个调度策略,并将其部署到cluster01和cluster02两个集群,使用权重拆分的方式部署,每个集群的权重为1,以保证两个集群的相同优先级。

    apiVersion: policy.karmada.io/v1alpha1kind: PropagationPolicymetadata:  name: hpa-example-pp  namespace: defaultspec:  placement:    clusterAffinity:      clusterNames:      - cluster01      - cluster02    replicaScheduling:      replicaDivisionPreference: Weighted      replicaSchedulingType: Divided      weightPreference:        staticWeightList:        - targetCluster:            clusterNames:            - cluster01          weight: 1        - targetCluster:            clusterNames:            - cluster02          weight: 1  preemption: Never  propagateDeps: true  resourceSelectors:  - apiVersion: apps/v1    kind: Deployment    name: hpa-example    namespace: default  - apiVersion: v1    kind: Service    name: hpa-example    namespace: default

support.huaweicloud.com/bestpractice-ucs/ucs_03_0011.html