Giter Site home page Giter Site logo

Comments (8)

ahakanbaba avatar ahakanbaba commented on August 27, 2024 1

Would this code help to understand the difference between capacity and allocatable ?

 // Set Allocatable.
 node.Status.Allocatable = make(api.ResourceList)
 for k, v := range node.Status.Capacity {
    value := *(v.Copy())
    if kl.reservation.System != nil {
       value.Sub(kl.reservation.System[k])
    }
    if kl.reservation.Kubernetes != nil {
       value.Sub(kl.reservation.Kubernetes[k])
    }
    if value.Sign() < 0 {
       // Negative Allocatable resources don't make sense.
       value.Set(0)
    }
    node.Status.Allocatable[k] = value
 }

This is from here https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/kubelet_node_status.go#L459

Reservation is defined here
https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/kubelet.go#L974


 // reservation specifies resources which are reserved for non-pod usage, including kubernetes and
 // non-kubernetes system processes.
 reservation kubetypes.Reservation

from kube-state-metrics.

brancz avatar brancz commented on August 27, 2024

Interesting, in the code we seem to use the correct values and the values from the status struct should reflect the state you are looking for. I believe these numbers come from cAdvisor through the apiserver. I believe we have seen that behaviour from cAdvisor before, right @fabxc?

from kube-state-metrics.

brancz avatar brancz commented on August 27, 2024

Looking further into it there are quite a few more constants that describe memory resources. We should figure out which ones are applicable for the purpose you described. At least from our current naming I would expect the same numbers/behavior as you do @rvrignaud .

from kube-state-metrics.

brancz avatar brancz commented on August 27, 2024

Looking at my local dev cluster it looks like the resources we take should be correct, but I get the same numbers for capacity/allocatable as well directly from the apiserver.

{
  "capacity": {
    "alpha.kubernetes.io/nvidia-gpu": "0",
    "cpu": "1",
    "memory": "1021160Ki",
    "pods": "110"
  },
  "allocatable": {
    "alpha.kubernetes.io/nvidia-gpu": "0",
    "cpu": "1",
    "memory": "1021160Ki",
    "pods": "110"
  },
  ...
}

from kube-state-metrics.

fabxc avatar fabxc commented on August 27, 2024

I recall seeing this issue before and it being an issue in cAdvisor.

Found something similar at least: google/cadvisor#1404

from kube-state-metrics.

therc avatar therc commented on August 27, 2024

Yes, by default capacity and allocatable are the same, but a good administrator will reserve some resources from the node for system processes (systemd, journald, sshd and in many cases kubelet/kube-proxy).

from kube-state-metrics.

andyxning avatar andyxning commented on August 27, 2024

@rvrignaud @brancz Kubelet now supports two command line arguments: --kube-reserved and --system-reserved. By setting any of both, node allocatable and capacity should be different. Just as what has been mentioned in comment 264933854 by @fabxc.

For now, the value for node allocatable and capacity are correct.

Maybe we can close this. @rvrignaud

from kube-state-metrics.

rvrignaud avatar rvrignaud commented on August 27, 2024

Closing it

from kube-state-metrics.

Related Issues (20)

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.