Kubernetes 中容器的自动资源调整工具
Kondense is an automated resource sizing tool. It runs as a sidecar in kubernetes pods.
Kondense uses memory pressure to apply just the right amount of memory on a container to page out the unused memory while not getting out-of-memory killed.How is memory calculated ?
Kondense resizes CPU based on CPU usage, default to 80%.How is CPU calculated ?
InPlacePodVerticalScaling enabled./sys/fs/cgroup/memory.pressure exists in the container to verify it.You can build your containers from the image alpine to be sure.
Try the example on minikube:
minikube start --kubernetes-version=v1.29.2 --feature-gates=InPlacePodVerticalScaling=true
kubectl apply -f https://raw.githubusercontent.com/unagex/kondense/main/example/nginx.yamlLet's say we have a pod running nginx that we want to Kondense:
apiVersion: v1
kind: Pod
metadata:
name: kondense-test
spec:
serviceAccountName: nginx-user
containers:
- name: nginx
image: nginx:latest
resources:
limits:
cpu: 100m
memory: 100MAdd Kondense as a sidecar:
apiVersion: v1
kind: Pod
metadata:
name: kondense-test
spec:
serviceAccountName: nginx-user
containers:
- name: nginx
image: nginx:latest
resources:
limits:
cpu: 0.1
memory: 100M
- name: kondense
image: kondense/kondense:1.1.0
resources:
limits:
cpu: 80m
memory: 50MAfter adding the kondense container, the nginx container resources are updated without any container restart.
Notes:
Guaranteed. In other words, we need to add resources limits for each containers.nginx-user should have the following rules:rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch", "patch"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create"]Kondense is configurable via environment variables in the kondense container.
...
- name: kondense
image: kondense/kondense:1.1.0
resources:
limits:
cpu: 80m
memory: 50M
env:
- name: _MEMORY_MIN
value: "100m"If we have a container named nginx in our pod, the variable name should be NGINX_MEMORY_MIN.
| Name | Default value | Description |
|---|---|---|
| EXCLUDE | "" | Comma separated list of containers to not kondense. |
| Name | Default value | Description |
|---|---|---|
| \_MEMORY_MIN | 50M | Minimum memory of the container. Kondense will never resize below that limit. |
| \_MEMORY_MAX | 100G | Maximum memory of the container. Kondense will never resize above that limit. |
| \_MEMORY_TARGET_PRESSURE | 10000 | Target memory pressure in microseconds. Kondense will take corrective actions to obtain it. |
| \_MEMORY_INTERVAL | 10 | Kondense targets cumulative memory delays over the sampling period of this interval in seconds. |
| \_MEMORY_MAX_INC | 0.5 | Maximum memory increase for one correction. e.g. 0.5 is a 50% increase. |
| \_MEMORY_MAX_DEC | 0.02 | Maximum memory decrease for one correction. e.g. 0.02 is a 2% decrease. |
| \_MEMORY_COEFF_INC | 20 | Coeff to increase memory when the memory pressure is bigger then the target memory pressure. |
| \_MEMORY_COEFF_DEC | 10 | Coeff to decrease memory when the memory pressure is smaller then the target memory pressure. |
| Name | Default value | Description |
|---|---|---|
| \_CPU_MIN | 0.08 | Minimum CPU of the container. Kondense will never resize below that limit. |
| \_CPU_MAX | 100 | Maximum CPU of the container. Kondense will never resize above that limit. |
| \_CPU_MAX_INC | 0.5 | Maximum CPU increase for one correction. e.g. 0.5 is a 50% increase. |
| \_CPU_MAX_DEC | 0.1 | Maximum CPU decrease for one correction. e.g. 0.1 is a 10% decrease. |
| \_CPU_TARGET_AVG | 0.8 | Target CPU average for the container. It is from 0 to 1. e.g. 0.8 means a target cpu usage of 80%. |
| \_CPU_INTERVAL | 6 | CPU interval in seconds to calculate the CPU average. Each interval last 1 second. |
| \_CPU_COEFF | 6 | Used to calculate the new cpu limit when a cpu increase is needed. The higher the coeff, the higher the new cpu limit. |
暂无开放 Issues,或尚未同步最近议题。