I have many services. In a day, a few services are busy for about ten hours, while most other services are idle or use a small amount of cpu.
In the past, I put all services in a virtual machine with two cpus, and scale by cpu usage, there are two virtual machine at the busiest time, but most of the time there is only one.
| services | instances | busy time in a day | cpu when busy (core/service) |
cpu when idle (core/service) |
|---|---|---|---|---|
| busy services | 2 | 8~12 hours | 0.5~1 | 0.1~0.5 |
| busy services | 2 | 8~12 hours | 0.3~0.8 | 0.1~0.3 |
| inactive services | 30 | 0~1 hours | 0.1~0.3 | < 0.1 |
Now, I want to put them in kubernetes, each node has two CPUs, and use node autoscaling and HPA, in order to make the node autoscaling, I must set requests CPU for all services, which is exactly the difficulty I encountered.
This is my setting.
| services | instances | busy time | requests cpu (cpu/service) |
total requests cpu |
|---|---|---|---|---|
| busy services | 2 | 8~12 hours | 300m | 600m |
| busy services | 2 | 8~12 hours | 300m | 600m |
| inactive services | 30 | 0~1 hours | 100m | 3000m |
Note: The inactive service requests CPU is set to 100m because it will not work well if it is less than 100m when it is busy.
With this setting, the number of nodes will always be greater than three, which is too costly. I think the problem is that although these services require 100m of CPU to work properly, they are mostly idle.
I really hope that all services can autoscaling, I think this is the benefit of kubernetes, which can help me assign pods more flexibly. Is my idea wrong? Shouldn't I set a request CPU for an inactive service?
Even if I ignore inactive services. I find that kubernetes more often has more than two nodes. If I have more active services, even in off-peak hours, the requests CPU will exceed 2000m. Is there any solution?