Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda