# This manifest deploys a PhoenixAI cluster with 3 FEs and CN with autoscaling enabled.
# CN nodes are optional components of StarRocks.
# You can increase the number of CN nodes to elastically scale compute resources without
# changing the data distribution in your PhoenixAI cluster.

apiVersion: phoenixdata.ai/v1
kind: PhoenixAICluster
metadata:
  name: a-phoenixai-with-cn   # change the name if needed.
spec:
  phoenixAIFeSpec:
    image: us-west1-docker.pkg.dev/phoenix-ai-images/enterprise/fe-ubuntu:4.1.5-ee
    replicas: 3
    # If you just want to start a running PhoenixAI cluster, you can set a smaller request/limit, such as 1 core and 2GB.
    # See https://docs.starrocks.io/docs/deployment/plan_cluster/#cpu-and-memory for more information about how to configure CPU and memory in production.
    limits:
      cpu: 4
      memory: 8Gi
    requests:
      cpu: 4
      memory: 8Gi
    # storageVolumes is optional. If you don't specify it, emptyDir will be used to store FE meta and log, and the files
    # and directories written to the volume will be completely lost upon container restarting.
    storageVolumes:
    - name: fe-meta
      # storageClassName: ""  # If storageClassName is not set, Kubernetes will use the default storage class.
      # FE container stop running if the disk free space which the fe meta directory residents, is less than 5Gi.
      storageSize: 10Gi
      mountPath: /opt/starrocks/fe/meta
    - name: fe-log
      # storageClassName: ""  # If storageClassName is not set, Kubernetes will use the default storage class.
      storageSize: 5Gi
      mountPath: /opt/starrocks/fe/log
  phoenixAICnSpec:
    image: us-west1-docker.pkg.dev/phoenix-ai-images/enterprise/cn-ubuntu:4.1.5-ee
    # If you just want to start a running PhoenixAI cluster, you can set a smaller request/limit, such as 1 core and 2GB.
    # See https://docs.starrocks.io/docs/deployment/plan_cluster/#cpu-and-memory for more information about how to configure CPU and memory in production.
    limits:
      cpu: 4
      memory: 8Gi
    requests:
      cpu: 4
      memory: 8Gi
    # storageVolumes is optional. If you don't specify it, emptyDir will be used to store CN cache data and log, and be aware
    # that the files and directories written to the volume will be completely lost upon container restarting.
    storageVolumes:
    - name: cn-cache-data
      storageClassName: "hostPath"  # If storageClassName is not set, Kubernetes will use the default storage class.
      hostPath:
        path: /storage
      storageSize: 1Ti
      mountPath: /opt/starrocks/cn/storage
    - name: cn-log
      # storageClassName: ""  # If storageClassName is not set, Kubernetes will use the default storage class.
      storageSize: 1Gi
      mountPath: /opt/starrocks/cn/log
    # autoScalingPolicy is optional. If you don't specify it, the CN nodes will not be auto-scaled.
    autoScalingPolicy: # Automatic scaling policy of the CN cluster.
      maxReplicas: 10 # The maximum number of CNs is set to 10.
      minReplicas: 1 # The minimum number of CNs is set to 1.
      # operator creates an HPA resource based on the following field.
      # see https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/ for more information.
      hpaPolicy:
        metrics: # Resource metrics
          - type: Resource
            resource:
              name: memory  # The average memory usage of CNs is specified as a resource metric.
              target:
                # The elastic scaling threshold is 60%.
                # When the average memory utilization of CNs exceeds 60%, the number of CNs increases for scale-out.
                # When the average memory utilization of CNs is below 60%, the number of CNs decreases for scale-in.
                averageUtilization: 60
                type: Utilization
          - type: Resource
            resource:
              name: cpu # The average CPU utilization of CNs is specified as a resource metric.
              target:
                # The elastic scaling threshold is 60%.
                # When the average CPU utilization of CNs exceeds 60%, the number of CNs increases for scale-out.
                # When the average CPU utilization of CNs is below 60%, the number of CNs decreases for scale-in.
                averageUtilization: 60
                type: Utilization
        behavior: #  The scaling behavior is customized according to business scenarios, helping you achieve rapid or slow scaling or disable scaling.
          scaleUp:
            policies:
              - type: Pods
                value: 1
                periodSeconds: 10
          scaleDown:
            selectPolicy: Disabled
