Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
Hide node core count from docker container

I am currently building a system that run services in individual deployments in a kubernetes cluster and require the limitation of visible cores inside the container.

Node Specs:
8 Cores
16 GB memory

When I deploy, log into the container and inspect the core count with python's multiprocessing module I get the following output:

In [1]: import multiprocessing
In [2]: multiprocessing.cpu_count()
Out[2]: 8

This output is correct seeing that my node has 8 cores.

What I would like is for the container to return a core count of 1 as the core count when running the same multiprocessing.cpu_count() command.

The example use case for this is as follows:

Developer creates an api services running python and gunicorn, gunicorn's default behaviour is to create workers for the number of cores available.

The above will be a problem when the pod is only allowed 100m CPU and 300m Mem as the 8 workers will at some point fill up the memory and the pod will crash, I also would like to hide this for the sake of potential confusion and unexpected behaviour when detecting resources programmatically.

I have tried using the --cpuset-cpus=0 flag as it stood out as a potential solution, but from what I understand and experienced is that this will merely limit the container to the specified core, which does not hide the other 7 cores.

Is there any way of doing this, any help will be appreciated.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could have an environment variable NUM_CPUS that if it's present you should use it instead of multiprocessing.cpu_count(). Something like:

import os

num_cpus = os.getenv("NUM_CPUS")
if num_cpus is not None:
    cpu_count = max(round(num_cpus), 1)
else:
    cpu_count = multiprocessing.cpu_count()       
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!