12/01/2024 - KUBERNETES
Kubernetes sınırları bir konteynerin kullanabileceği maksimum CPU/bellek miktarını tanımlar. Bu kesin sınırdır ve belirlenen sınırların dışına çıkmaz. İstekler bir konteynerin kullanabileceği garanti edilen minimum CPU/bellek miktarını tanımlar.
Bir K8S kümesinin (cluster) toplam CPU kapasitesi, küme içindeki tüm kullanılabilir düğümler (node) tarafından kullanılan maksimum CPU çekirdeği miktarıdır.
3 düğümlü bir küme olduğunu varsayalım. İlk düğüm 2 çekirdeğe, ikinci düğüm 2 çekirdeğe ve üçüncü düğüm 1 çekirdeğe sahiptir. Buna göre bir K8S kümesinin toplam CPU kapasitesi maksimum 5 CPU çekirdeğidir (2+2+1). 1,7 çekirdek gerektiren bir pod varsa, limiti 1 çekirdek olduğundan üçüncüye planlanmayacaktır. Bunun yerine birinci veya ikinci düğüme programlanacaktır.
İyi bir görsel açıklama için lütfen sysdig linkini ziyaret edin. Daha fazla bilgi için Kubernetes (namespace) ve Kubernetes (pod/container) linklerini ziyaret edin.
$ minikube start --memory 4000 --cpus=2
- Using the hyperkit driver based on user configuration
- Starting "minikube" primary control-plane node in "minikube" cluster
- Creating hyperkit VM (CPUs=2, Memory=4000MB, Disk=20000MB) ...
- Preparing Kubernetes v1.30.0 on Docker 26.0.1 ...
$ kubectl describe node
...
Capacity:
cpu: 2
memory: 3912944Ki
Allocatable:
cpu: 2
memory: 3912944Ki
...
$ kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
minikube 295m 14% 1495Mi 39%
CPU(cores) - 295m means 295 millicpu. If 1000m equals to 1 CPU, thus 295m means 29.5% of 1 CPU.
CPU% - The total CPU usage percentage of the node which is 14% in this case.
MEMORY(bytes) - The total memory usage of the node which 1495MB (1.495GB) in this case.
MEMORY% - The total memory usage percentage of the node which is 39% in this case.
apiVersion: apps/v1
kind: Deployment
metadata:
name: gomax-deployment
namespace: default
labels:
app: gomax
spec:
replicas: 1
selector:
matchLabels:
app: gomax
template:
metadata:
labels:
app: gomax
spec:
containers:
- name: golang
image: me/gomax:latest
ports:
- containerPort: 8000
resources:
limits:
cpu: 1000m
memory: 1000Mi
requests:
cpu: 750m
memory: 750Mi
$ kubectl describe node
...
Non-terminated Pods: (9 in total)
Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits Age
--------- ---- ------------ ---------- --------------- ------------- ---
default gomax-deployment 750m (37%) 1 (50%) 750Mi (19%) 1000Mi (26%) 16s
...