GithubHelp home page GithubHelp logo

unagex / kondense Goto Github PK

View Code? Open in Web Editor NEW
154.0 2.0 3.0 245 KB

Automated resources sizing tool for containers in kubernetes

License: GNU General Public License v3.0

Dockerfile 1.52% Makefile 0.78% Go 96.61% Shell 1.09%
kubernetes memory memory-management

kondense's Introduction

Kondense

Go version Go Report Card GitHub release

drawing

Kondense is an automated resource sizing tool. It runs as a sidecar in kubernetes pods.

Background

Memory

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 ?

CPU

Kondense resizes CPU based on CPU usage, default to 80%.
How is CPU calculated ?

Requirements

On Kubernetes

  • The Kubernetes cluster must run on Linux.
  • Containerd version >= 1.6.9.
  • Kubernetes should have the feature gate InPlacePodVerticalScaling enabled.

On Containers

  • Containers should include the linux kernel version >= 4.20. Ensure the file /sys/fs/cgroup/memory.pressure exists in the container to verify it.

You can build your containers from the image alpine to be sure.

Example

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.yaml

Let'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: 100M

Add 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: 50M

After adding the kondense container, the nginx container resources are updated without any container restart.

Notes:

  1. The pod should have a QoS of Guaranteed. In other words, we need to add resources limits for each containers.
  2. The service account nginx-user should have the following rules:
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch", "patch"]
  - apiGroups: [""]
    resources: ["pods/exec"]
    verbs: ["create"]

Configuration

Kondense is configurable via environment variables in the kondense container.

Example

    ...
    - name: kondense
      image: kondense/kondense:1.1.0
      resources:
        limits:
          cpu: 80m
          memory: 50M
      env:
      - name: <CONTAINER NAME>_MEMORY_MIN
        value: "100m"

If we have a container named nginx in our pod, the variable name should be NGINX_MEMORY_MIN.

Environment variables

Global

Name Default value Description
EXCLUDE "" Comma separated list of containers to not kondense.

Memory

Name Default value Description
<CONTAINER NAME>_MEMORY_MIN 50M Minimum memory of the container. Kondense will never resize below that limit.
<CONTAINER NAME>_MEMORY_MAX 100G Maximum memory of the container. Kondense will never resize above that limit.
<CONTAINER NAME>_MEMORY_TARGET_PRESSURE 10000 Target memory pressure in microseconds. Kondense will take corrective actions to obtain it.
<CONTAINER NAME>_MEMORY_INTERVAL 10 Kondense targets cumulative memory delays over the sampling period of this interval in seconds.
<CONTAINER NAME>_MEMORY_MAX_INC 0.5 Maximum memory increase for one correction. e.g. 0.5 is a 50% increase.
<CONTAINER NAME>_MEMORY_MAX_DEC 0.02 Maximum memory decrease for one correction. e.g. 0.02 is a 2% decrease.
<CONTAINER NAME>_MEMORY_COEFF_INC 20 Coeff to increase memory when the memory pressure is bigger then the target memory pressure.
<CONTAINER NAME>_MEMORY_COEFF_DEC 10 Coeff to decrease memory when the memory pressure is smaller then the target memory pressure.

CPU

Name Default value Description
<CONTAINER NAME>_CPU_MIN 0.08 Minimum CPU of the container. Kondense will never resize below that limit.
<CONTAINER NAME>_CPU_MAX 100 Maximum CPU of the container. Kondense will never resize above that limit.
<CONTAINER NAME>_CPU_MAX_INC 0.5 Maximum CPU increase for one correction. e.g. 0.5 is a 50% increase.
<CONTAINER NAME>_CPU_MAX_DEC 0.1 Maximum CPU decrease for one correction. e.g. 0.1 is a 10% decrease.
<CONTAINER NAME>_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%.
<CONTAINER NAME>_CPU_INTERVAL 6 Target CPU average for the container. It is from 0 to 1. e.g. 0.8 means a target cpu usage of 80%.
<CONTAINER NAME>_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.

More

kondense's People

Contributors

mathieucesbron avatar antoinemath avatar

Stargazers

Greg Martenson avatar Matei Popa avatar William Huang avatar  avatar Florian Daguin avatar GROARK avatar  avatar Duy avatar  avatar Thomas Martin avatar Monty Rhodes avatar  avatar  avatar H.Hedhly avatar Edward Samuel Pasaribu avatar Gustavo Jeronimo avatar  avatar  avatar Greg Bray avatar Marcelo Andrade avatar Alex Chen avatar Aleksandar Djurdjic avatar Sam Rogers avatar Melwin Kieffer avatar lRamm avatar  avatar Corey avatar Borko avatar Tadeuš Varnas avatar Dimitrios Skarlatos avatar  avatar gleeco avatar Michal Muransky avatar  avatar Nikolay Kolev avatar Bishwa Thapa avatar Martin Dojcak avatar Kain avatar Mujahed Alaqqad avatar Shubham Jain avatar Caleb Woodbine avatar  avatar BTC avatar Dave C avatar Qiang-Liu avatar Bryan A. S. avatar Mark B avatar Florian Boulanger avatar Lukas M avatar  avatar Anton Patsev avatar Artem Nistratov avatar Alexey Yurchenko avatar MathieuCesbron avatar Vlad Feninets avatar David Gidwani avatar  avatar  avatar Vadim Rutkovsky avatar Stefano avatar  avatar Andrey Korablin avatar Ahmed AbouZaid avatar  avatar  avatar Nurbol Khamzauly avatar Joshua Thompson avatar  avatar Denis Zhdanov avatar Miguel Perez avatar Viacheslav Vasilyev avatar Daniel Moritz avatar Eugene Klimov avatar  avatar Novikov Bogdan avatar Diogo Silva avatar Vladislav Tropnikov avatar Ivan Goncharov avatar Vlad Gusev avatar Nicolai Antiferov avatar George Pchelkin avatar Vladyslav Papidokha avatar Pandry avatar Nik avatar Cornelius Wichering avatar  avatar Mike Unke avatar Peter Stewart avatar scott lewis avatar Bogdan Dinu avatar Stelian Ionescu avatar Tim avatar Miles Frankel avatar  avatar Tomás Beers avatar Drew Hess avatar Billy Laing avatar Tony Garcia avatar Bojan Zelic avatar Antonio Bri Pérez avatar

Watchers

 avatar MathieuCesbron avatar

kondense's Issues

Add option to kondense only cpu or kondense only memory

Right now, kondense is updating memory and cpu for each container in a pod.

An environment variable in the kondense container could make it so that we only update memory or cpu.

example:

      - name: kondense
        image: kondense/kondense:1.0.1
        resources:
          limits:
            cpu: 80m
            memory: 100M
        env:
        - name: STRESS-NG_MODE
          value: "cpu"
          # value: "cpu" || "memory" || "all"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.