Scale a Deployment Using a Horizontal Pod Autoscaler#

You can update a deployment to change the number of replicas as shown below. You may prefer to use an fixed number of replicas as described in Scale a Deployment Using Replicas.

Example Customization#

  1. Create an overlay structure as described in Customize ESS.

  2. Add the customization overlay:

    #kustomization.yaml
    
    ...
    
    resources:
      - ess-ldp-autoscaler.yaml
    
    #ess-ldp-autoscaler.yaml
    # ESS Autoscaling
    
    # This needs a Metrics server to be installed. See:
    # https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/
    # The command to install a metrics server is:
    # `kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml`
    
    # When the average CPU load is below 40 percent, the autoscaler tries to reduce the number of instances
    # in the deployment, to a minimum of nine which means it uses more than one machine.
    # When the load is greater than 40 percent, the autoscaler
    # tries to increase the number of instances in the deployment, up to a maximum of twenty.
    ---
    apiVersion: autoscaling/v1
    kind: HorizontalPodAutoscaler
    metadata:
      name: ess-ldp
    spec:
      maxReplicas: 20
      minReplicas: 9
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: ess-ldp
      # Average CPU usage across all LDP instances in the cluster.
      targetCPUUtilizationPercentage: 40