Giriş
Değerler iki şekilde verilebiliyor
1. Yüzde Olarak
2. Mutlak Değer Olarak
Yüzde Olarak
targetCPUUtilizationPercentage kullanılır. Tüm podlardaki ortalama CPU kullanımını alır belirtilen yüzde ile çarpar ve resources/requests alanında belirtilen değer ile karşılaştırırMutlak Değer Olarak
targetAverageUtilization kullanılır. Açıklaması şöyle
When a targetAverageValue or targetAverageUtilization is specified, the currentMetricValue is computed by taking the average of the given metric across all Pods in the HorizontalPodAutoscaler's scale target.
1. Yüzde Olarak
Örnek
Yüzde olarak hesaplarken şuna dikkat etmek lazım. Yani resources bölümlü altındaki requests değeri kullanılır. limit değeri kullanılmaz
The documentation states “Utilization is the ratio between the current usage of resource to the requested resources of the pod.”
Deployment şöyle olsun.
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld-deployment
spec:
template:
spec:
containers:
- name: hello-world
image: helloworld-webserver:v1.0.0
resources:
requests:
cpu: 10m
memory: 32Mi
limits:
cpu: 100m
memory: 64Mi
...HPA şöyle olsun. Burada yüzde olarak belirtirsek 10m değeri dikkate alınır. Eğer ortalama 8m'nin üzerine çıkarsa HPA çalışır
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: helloworld-deployment
spec:
maxReplicas: 4
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: helloworld-deployment
targetCPUUtilizationPercentage: 80Açıklaması şöyle.
Your HPA will start scaling the replicas up when average CPU utilization exceeds 8m, not 80m.
If you wanted your HPA to allow CPU utilization greater than the request before scaling up, you can simply specify a target utilization percentage greater than 100. In this example, to allow the utilization to reach 60m before scaling up, you could specify a target utilization percentage of 600.
2. Mutlak Değer Olarak
Örnek
Deployment şöyle olsun
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-deployment
namespace: default
labels:
app: order-deployment
spec:
selector:
matchLabels:
app: order-deployment
template:
metadata:
labels:
app: order-deployment
spec:
containers:
- name: order-service
image: ...
env:
- name: SPRING_DATASOURCE_URL
value: "jdbc:postgresql://postgres-service:5432/postgres?currentSchema=order
resources:
limits:
cpu: "500m"
memory: "1024Mi"
requests:
cpu: "200m"
memory: "256Mi"Şöyle yaparız. Burada 200m istenmiş. Eğer ortalama 85m'nin üzerine çıkarsa HPA çalışır
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: order-deployment-hpa
namespace: default
labels:
app: order-deployment
spec:
scaleTargetRef:
kind: Deployment
name: order-deployment
apiVersion: apps/v1
minReplicas: 2
maxReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 85
Hiç yorum yok:
Yorum Gönder