30 Ocak 2022 Pazar

Kubernetes Resource Requirements

Giriş
İki çeşir Resource var. 
1. Object'ler için Resource. Resource Requirements Pod veya Deployment gibi bir şey için belirtilebilir. 
2. System için Resource

Şeklen şöyle


LimitRange ve ResourceQuotas
Açıklaması şöyle
... Kubernetes provides two resource-level policies: LimitRange and ResourceQuotas. LimitRanges can be used to constrain individual resource usage (e.g., max 2 CPUs per pod), whereas ResourceQuota controls the aggregate resource usage (e.g., a total of 20 CPU in the dev namespace).
kind: ResourceQuota yazısına bakabilirsiniz

Resource Consumption Limits
Açıklaması şöyle. requests "en az", limits ise "en fazla" değerleri belirtir.
Kubernetes defines ‘requests’ and ‘limits’ in its resource utilization category. Requests represent the minimum resources an application needs to run, and limits define the maximum resources. No control over the resources also means we are not monitoring the application. We can specify the resource limits in the deployment YAML.
CPU
Şeklen şöyle


Bu konuda  düstur şöyle. Ya Burstable ya da Guaranteed QoS kullanılması öneriliyor.
Pods are guaranteed to get the amount of CPU they request, they may or may not get additional CPU time (depending on the other jobs running).
...
Always set CPU requests. This is the baseline and it is the only thing you can count on.

- Tim Hockin, Kubernetes Maintainer
1. Eğer CPU limit belirtilmişse ve worker node üzerinde bu kadar kaynak yoksa, Pod çalıştırılmaz. "Pending" olarak görürüz. "kubectl describe pod" ile  bakarsak sebep FailedScheduling olarak görülür.

2. Eğer CPU limit belirtilmemişse açıklaması şöyle
- As our pod’s container has not been given any upper threshold limit it could use all of the CPU resources available on the Node where it is running.
- There can also be a situation where our Pod’s container is running in some given namespace, which has some default CPU limit. In this case, our container will automatically be assigned the default limit.
- A LimitRange parameter can be used by our cluster administrator to specify a default value for the CPU limit.

Limit Koyma veya Koymama
Bence güzel bir açıklama şöyle. Burada her iki uygulamaya limit koymama, sadece birine koyma durumları tartışılıyor. Neticede alt sınırı belirlemek her zaman iyidir.
Why they are saying CPU limits are bad

Let's start with an example where we have two pods, A and B. Pod A is always low on CPU, it uses from 100m to 200m, while B is an application constantly receiving requests and keeps its CPU usage medium to high, from 300m to 500m. Let's also suppose our node has 1000m available for pods.

This is fine because the worst-case scenario is 700m (A 200m + B 500m), we have 300m to spare. The issue is that during any unpredicted event, things could go wrong. Let's consider some examples:
  1. A and B don't have any requests or limits. If pod B starts spending lots of CPU time, like 980m, then A is going to starve with only 20m.
  2. We set up CPU limits for B at 500m, now A won't starve because B has limits. Great, but if A is consuming 100m, and B is consuming 500m then we have 400m unused even though B could be using it during these unpredicted events.
  3. Instead of setting up limits for B, let's set up requests for A. Now A requests 200m for CPU and B has no limits. When B starts spending lots of CPU, A won't be affected because it is guaranteed it's always going to have 200m for him.
The second example shows how setting limits could waste resources that could easily be used. The third example is not yet ideal, we should set requests for both pods, but the idea is to show that limits could waste your resources, and if you set proper requests for every pod then no one is going to starve, so you don't need them.
M Son Eki
Açıklaması şöyle
The unit suffix m stands for “thousandth of a core,”
Gi Son Eki
Açıklaması şöyle. Yani Gi Gibibytes anlamına geliyor.
... (G) is power of ten, while the other one (Gi) is power of two. So,
- 10^3 is power of ten. the result is 1000, or 1G
- 2^10 is power of two. the result is 1024, or 1Gi

Örnek - cpu
Şöyle yaparız. Burada al sınıf 0.5 CPU, üst sınır ise 1 tam CPU, 
resources:
limits: cpu: "1000m" memory: "1Gi" requests: cpu: "500m" memory: "500Mi"
Örnek - memory
Şöyle yaparız
apiVersion: v1
kind: Pod
metadata:
  name: static-web
  labels:
    role: myrole
spec:
  containers:
  - name: nginx
    image: nginx
    resources:
      requests:
        memory: "1Mi"
        cpu: 0.2
      limits:
        memory: "1Gi"
        cpu: 1
    envFrom:
    - secretRef:
        name: testsecret


Hiç yorum yok:

Yorum Gönder

Cluster Propotional Autoscaler - ReplicaSet Ekler/Siler

Giriş Açıklaması şöyle CPA aims to horizontally scale the number of Pod replicas based on the cluster’s scale. A common example is DNS ser...