2

Consider this scenario:

  • 1 worker node with 4 CPU cores
  • 2 pods there, one of which is some CPU intensive bg task, another one is a web server with unpredictable CPU load during the day.

I need to somehow tell k8s that my web server has higher priority than bg task in terms of CPU. Because I want to get is 100% load by bg task when there is no load on web server and e.g. 25/75% load when web server is on peak.

I tried to do something with resource requests and limits, but it works differently than what I expected. For example if I limit bg task to one core and then dedicate 3 cores to web server to handle highload peaks, it will obviously mean that CPU in my cluster is under loaded most of the time and I want to maximize utilization. If I do not set limits for CPU for both pods at all, on peaks web server works slower than needed.

Another approach which also does not work - is to schedule changes in resource requests to adapt to times when web server load is increasing, because peaks for web server are unpredictable and rather short, so I need a server up and running waiting for them.

So considering I want to use k8s as a cluster orchestrator, is there a way to define CPU priorities for particular pods?

1
  • Research tells me you can use PriorityClasses, Pod priority and resource requests and limits to manage this. Commented Mar 28 at 13:25

2 Answers 2

0

According to https://stackoverflow.com/a/58296752 you need to set requests.cpu really low for the background pod (like requests.cpu: 50m, limits.cpu: 4000m) and high for the foreground pod (like requests.cpu 3950m, limits.cpu: 4000m). That will make the background pod wait until there is unused CPU available on best effort basis.

0

pod.spec.priorityClass can be used for influencing which pods get evicted in case of the cluster being overloaded (according to pod.spec.resources). But the k8s scheduler merely decides which pods go on which nodes. It does not influence the second-to-second CPU scheduling during the lifetime of the pod - this is the domain of the Linux Kernel.

If you have a known-to-be-cpu-intensive pod, it would make sense to run it with nice on the command line to give it an actually lower CPU priority.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.