Kubernetes基于时间计划的资源请求/限制

huangapple go评论87阅读模式
英文:

Kubernetes resource requests/limits based on time plan

问题

我们可以为Pod定义内存和CPU的请求/限制,这不是问题。是否可以根据时间计划来定义不同的内存和CPU请求/限制?我考虑类似以下的方式:

  1. 早上8 - 晚上8
  2. - CPU请求 0.5,限制 2
  3. - 内存请求 1Gi,限制 2Gi
  4. 晚上801 - 早上759
  5. - CPU请求 0.1,限制 0.5
  6. - 内存请求 500Mi,限制 1Gi

这可以帮助我们根据白天高性能实时处理和夜晚相同Pod的较低性能来进行性能调优。您是否解决过类似的挑战?

英文:

We can define memory and cpu requests/limits for pods, it is not a problem. Is it possible to define different memory and cpu requests/limits based on time plan? I think about something like that:

  1. 8AM - 8PM
  2. - CPU request 0.5, limit 2
  3. - RAM request 1Gi, limit 2Gi
  4. 8:01PM - 7:59AM
  5. - CPU request 0.1, limit 0.5
  6. - RAM request 500Mi, limit 1Gi

It can help us with tuning of performance based on e.g. high performance real-time processing during the day and lower performance the same pods during the night. Did you solve similar challenge?

答案1

得分: 2

这不是 Kubernetes 核心支持的功能。

这个问题已经讨论过很多次(例如这里那里)。

我可以看到两种解决这个挑战的方法:

  • 使用一个 cronJob 和一个包含 kubectl 二进制文件的镜像来调整资源的上下限
  1. apiVersion: batch/v2alpha1
  2. kind: CronJob
  3. metadata:
  4. name: patch-memory
  5. spec:
  6. schedule: "0 8 * * *"
  7. jobTemplate:
  8. spec:
  9. template:
  10. spec:
  11. containers:
  12. - name: scale
  13. image: <your-repo>/kubectl:<tag>
  14. command:
  15. - kubectl.sh
  16. - kubectl
  17. - patch
  18. - deployment
  19. - <your deployment>
  20. - --patch
  21. - '{"spec": {"template": {"spec": {"containers": [{"name": "<your container>": {"resources": {"requests": {"memory": "XXXMi"}}}}]}}}}'
  22. restartPolicy: OnFailure
  • 使用自定义控制器,比如这个这个,或者你可以在线找到其他项目。我自己没有使用过这些项目。

你还可以考虑使用水平 Pod 自动扩展:这允许你根据资源使用情况在 deploymentstatefulsets 上添加更多的 pod

另一方面,你也可以使用VPA。它会根据工作负载的资源使用情况动态设置资源请求/限制,不像你提到的那种 cron 风格。

英文:

This is not something supported by kubernetes core.

This has been discussed many times (here or there for example)

I can see two ways of solving this challenge :

  • Using a cronJob and an image that embeds a kubectl binary to patch up/down your ressources
  1. apiVersion: batch/v2alpha1
  2. kind: CronJob
  3. metadata:
  4. name: patch-memory
  5. spec:
  6. schedule: &quot;0 8 * * *&quot;
  7. jobTemplate:
  8. spec:
  9. template:
  10. spec:
  11. containers:
  12. - name: scale
  13. image: &lt;your-repo&gt;/kubectl:&lt;tag&gt;
  14. command:
  15. - kubectl.sh
  16. - kubectl
  17. - patch
  18. - deployment
  19. - &lt;your deployment&gt;
  20. - --patch
  21. - &#39;{&quot;spec&quot;: {&quot;template&quot;: {&quot;spec&quot;: {&quot;containers&quot;: [{&quot;name&quot;: &quot;&lt;your container&gt;&quot;: {&quot;resources&quot;: {&quot;requests&quot;: {&quot;memory&quot;: &quot;XXXMi&quot; }}}}]}}}}&#39;
  22. restartPolicy: OnFailure
  • Using a custom controler like this one or this one or others you can find online. I have no experience using those projects myself.

You could also consider using Horizontal Pod Autoscaling : This allows you to add more pod on a deployment or statefulsets based on resources usage.

On another hand, you could also use VPA. This will dynamically set resources requests/limits on your workload based on their resources usage - not in a cron style like you mentioned

huangapple
  • 本文由 发表于 2023年7月10日 22:43:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76654867.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定