Skip to content

HPA support for pod-level resource specifications #132237

Open
@laoj2

Description

@laoj2

What would you like to be added?

With k8s 1.34, PodLevelResources will allow users to specify resources on Pod level instead of on Container level. More info on how this works in the KEP

This is a placeholder/umbrella issue, similar to VPA's kubernetes/autoscaler#7571

Why is this needed?

HPA needs to be able to correctly calculate the resources requested by a pod, when it's defined at pod or container level. Today, it calculates the pod requests by aggregating the requests of all containers within a pod:

func calculatePodRequests(pods []*v1.Pod, container string, resource v1.ResourceName) (map[string]int64, error) {
requests := make(map[string]int64, len(pods))
for _, pod := range pods {
podSum := int64(0)
// Calculate all regular containers and restartable init containers requests.
containers := append([]v1.Container{}, pod.Spec.Containers...)
for _, c := range pod.Spec.InitContainers {
if c.RestartPolicy != nil && *c.RestartPolicy == v1.ContainerRestartPolicyAlways {
containers = append(containers, c)
}
}
for _, c := range containers {
if container == "" || container == c.Name {
if containerRequest, ok := c.Resources.Requests[resource]; ok {
podSum += containerRequest.MilliValue()
} else {
return nil, fmt.Errorf("missing request for %s in container %s of Pod %s", resource, c.Name, pod.ObjectMeta.Name)
}
}
}
requests[pod.Name] = podSum
}
return requests, nil
}

We could use https://github.com/kubernetes/kubernetes/blob/988cf21f0975cf95444a619481c13d2503d8ec6a/staging/src/k8s.io/component-helpers/resource/helpers.go, to calculate the pod requests in HPA.

Metadata

Metadata

Assignees

Labels

kind/featureCategorizes issue or PR as related to a new feature.sig/autoscalingCategorizes an issue or PR as relevant to SIG Autoscaling.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions