Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] limit cpu/memory resource on node #13

Closed
ravirdv opened this issue Apr 16, 2019 · 8 comments
Closed

[Feature] limit cpu/memory resource on node #13

ravirdv opened this issue Apr 16, 2019 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed wontfix This will not be worked on

Comments

@ravirdv
Copy link

ravirdv commented Apr 16, 2019

Currently when runningkubectl describe nodes, node capacity is shown same as host machine. It would be great to have a way to specify cpu/memory limit for node.

@iwilltry42
Copy link
Member

I'll have a look into this once #12 is finished (and merged), since it's changing a lot.

@iwilltry42 iwilltry42 self-assigned this Apr 16, 2019
@iwilltry42 iwilltry42 added the enhancement New feature or request label Apr 16, 2019
@iwilltry42
Copy link
Member

A brief thought on this. We can certainly set a memory limit on the node container that will have effect on the memory that can be used. But since the node containers have to run in privileged mode, they will still show you the whole memory available from the host system.

@ravirdv
Copy link
Author

ravirdv commented Apr 17, 2019

yes, that's what I observed. I tried setting mem_limits & cpus on node via docker-compose. I'd love to work on this, please let me know if you have any ideas on how to achieve this.

@iwilltry42
Copy link
Member

A possibility would be to find out which requirements k3s has exactly that it needs to run in privileged mode inside docker. Maybe it's possible to only add it to specific groups (--group-add) or give it some specific capabilities (--cap-add) instead of going all-in with --privileged?
Docker docs: https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities

@iwilltry42 iwilltry42 removed their assignment Apr 29, 2019
@iwilltry42 iwilltry42 added the help wanted Extra attention is needed label Apr 29, 2019
@iwilltry42 iwilltry42 changed the title limit cpu/memory resource on node [Feature] limit cpu/memory resource on node May 21, 2019
@iwilltry42
Copy link
Member

I'm pretty sure that we won't find a proper solution for this very soon 😞
Since the Kubernetes components kinda have to run privileged..

@iwilltry42
Copy link
Member

Closing this, since there's currently no possibility to achieve this...

@louiznk
Copy link
Contributor

louiznk commented Oct 13, 2020

Closing this, since there's currently no possibility to achieve this...

@iwilltry42 good news, there is solution, but it's in cAdvisor. I just make a PR and a related issue.
If it's validate I will make the other PR for integrate this to K3S (I don't know if it will be necessary to back port but it's a very small change) and after I can add this option on K3D for add the memory limit on docker.
I make some tests and it's working 🎉 (with a patched k3s and a custom k3d) (with a 32 GiB machine)

$ ./bin/k3d cluster create memlimit -p "80:80@server[0]" --image louiznk/k3s:v1.19.2-poc-mem  --agents 2 --no-lb --memory 3G          
INFO[0000] Created network 'k3d-memlimit'               
INFO[0000] Created volume 'k3d-memlimit-images'         
INFO[0001] Creating node 'k3d-memlimit-server-0'        
...
$ kubectl top node                                                                                                                        
NAME                    CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
k3d-memlimit-agent-0    23m          0%     208Mi           6%        
k3d-memlimit-agent-1    22m          0%     165Mi           5%        
k3d-memlimit-server-0   57m          0%     536Mi           17%   
$ kubectl get node -o=jsonpath="{.items[*]['status.capacity.memory']}"                                                                    
3Gi 3Gi 3Gi

@iwilltry42
Copy link
Member

@louiznk , woah, you really went down a rabbit hole there!
Pretty cool, that you invested so much time into fixing this issue! :)
I directly subscribed to your PR and issue on cAdvisor and am looking forward to have this merged upstream.
Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants