--- title: Federated Horizontal Pod Autoscalers (HPA) --- {% capture overview %} {% include feature-state-alpha.md %} This guide explains how to use federated horizontal pod autoscalers (HPAs) in the federation control plane. HPAs in the federation control plane are similar to the traditional [Kubernetes HPAs](/docs/tasks/run-application/horizontal-pod-autoscale/), and provide the same functionality. Creating an HPA targeting a federated object in the federation control plane ensures that the desired number of replicas of the target object are scaled across the registered clusters, instead of a single cluster. Also, the control plane keeps monitoring the status of each individual HPA in the federated clusters and ensures the workload replicas move where they are needed most by manipulating the min and max limits of the HPA objects in the federated clusters. {% endcapture %} {% capture prerequisites %} * {% include federated-task-tutorial-prereqs.md %} * You are also expected to have a basic [working knowledge of Kubernetes](/docs/setup/) in general and [HPAs](/docs/tasks/run-application/horizontal-pod-autoscale/) in particular. The federated HPA is an alpha feature. The API is not enabled by default on the federated API server. To use this feature, the user or the admin deploying the federation control plane needs to run the federated API server with option `--runtime-config=api/all=true` to enable all APIs, including alpha APIs. Additionally, the federated HPA only works when used with CPU utilization metrics. {% endcapture %} {% capture steps %} ## Creating a federated HPA The API for federated HPAs is 100% compatible with the API for traditional Kubernetes HPA. You can create an HPA by sending a request to the federation API server. You can do that with [kubectl](/docs/user-guide/kubectl/) by running: ```shell cat <>>>>>> master will also work when used with federation. Care however will need to be taken that when [generating load on a target deployment](/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#step-three-increase-load), it should be done against a specific federated cluster (or multiple clusters) not the federation. ## Conclusion The use of federated HPA is to ensure workload replicas move to the cluster(s) where they are needed most, or in other words where the load is beyond expected threshold. The federated HPA feature achieves this by manipulating the min and max replicas on the HPAs it creates in the federated clusters. It does not directly monitor the target object metrics from the federated clusters. It actually relies on the in-cluster HPA controllers to monitor the metrics and update relevant fields. The in-cluster HPA controller monitors the target pod metrics and updates the fields like desired replicas (after metrics based calculations) and current replicas (observing the current status of in cluster pods). The federated HPA controller, on the other hand, monitors only the cluster-specific HPA object fields and updates the min replica and max replica fields of those in cluster HPA objects, which have replicas matching thresholds. For example, if a cluster has both desired replicas and current replicas the same as the max replicas, and averaged current CPU utilization still higher than the target CPU utilization (all of which are fields on local HPA object), then the target app in this cluster needs more replicas, and the scaling is currently restricted by max replicas set on this local HPA object. In such a scenario, the federated HPA controller scans all clusters and tries to <<<<<<< HEAD find clusters which do not have such a condition (meaning the the desired replicas are less than the max, and current averaged cpu utilization is lower then the threshold). If it finds such ======= find clusters which do not have such a condition (meaning the desired replicas are less than the max, and current averaged CPU utilization is lower then the threshold). If it finds such >>>>>>> master a cluster, it reduces the max replica on the HPA in this cluster and increases the max replicas on the HPA in the cluster which needed the replicas. There are many other similar conditions which the federated HPA controller checks and moves the max replicas and min replicas around the local HPAs in federated clusters to eventually ensure that the replicas move (or remain) in the cluster(s) which need them. For more information, see ["federated HPA design proposal"](https://github.com/kubernetes/community/pull/593). {% endcapture %} {% include templates/task.md %}