54

I'm running Chrome with xvfb on Debian 8. It works until I open a tab and try to load content. The process dies silently...

Fortunately, I have gotten it to run smoothly on my local docker using docker run --shm-size=1G.

There is a known bug in Chrome that causes it to crash when /dev/shm is too small.

I am deploying to Container engine, and inspecting the OS specs. The host OS has a solid 7G mounted to /dev/shm, but the actual container is only allocated 64M. Chrome crashes.

How can I set the size of /dev/shm when using kubectl to deploy to container engine?

posit labs
  • 8,951
  • 4
  • 36
  • 66
  • 1
    Possible duplicate of [How to increase shm size of a kubernetes container (--shm-size equivalent of docker)](https://stackoverflow.com/questions/43373463/how-to-increase-shm-size-of-a-kubernetes-container-shm-size-equivalent-of-doc) – posit labs Sep 07 '17 at 00:25
  • 1
    I just posted a similar question, relating to app engine flexible instead of container engine. https://stackoverflow.com/questions/46414587/how-to-change-the-size-of-dev-shm-in-app-engine-flexible – speedplane Sep 26 '17 at 00:34

2 Answers2

160

Mounting an emptyDir to /dev/shm and setting the medium to Memory did the trick!

spec:
  volumes:
  - name: dshm
    emptyDir:
      medium: Memory
  containers:
  - image: gcr.io/project/image
    volumeMounts:
      - mountPath: /dev/shm
        name: dshm
posit labs
  • 8,951
  • 4
  • 36
  • 66
  • I'm having a [similar issue](https://stackoverflow.com/questions/47401805/howto-set-docker-swarm-runtime-volume-size-dev-shm), but with docker swarm. I don't see `spec:` or `containers:` entries in the docker-compose [reference](https://docs.docker.com/compose/compose-file/). How does this map to the [volumes spec](https://docs.docker.com/compose/compose-file/#volumes)? – Nutritioustim Nov 20 '17 at 22:03
  • I recommend posting a new question that is specific to docker swarm – posit labs Jan 19 '18 at 18:30
  • 2
    Thank you!!! One truly cannot configure options to the docker launch in the kube config (and the devs are consistently obtuse about not understanding the need for this). Your config has our docker-ized selenium test no longer randomly crashing. – welch Mar 08 '18 at 23:46
  • 7
    but where to constrains the size of emptyDir? – WeiChing 林煒清 Jun 19 '18 at 12:25
  • 2
    Size limit is being worked on here: https://github.com/kubernetes/kubernetes/pull/63641 – Mitar Aug 09 '18 at 08:12
  • Be aware that sizeLimit on the emptyDir will result in pod evictions if the limit is exceeded. This is much worse behavior than memory-hungry apps crashing. – bu11d0zer Apr 04 '19 at 23:45
  • It worked for me on a Kubernetes (AWS EKS) cluster. Thanks SO MUCH – EnriqueH Nov 28 '20 at 11:41
  • 3
    Setting the size should be possible now via https://github.com/kubernetes/kubernetes/pull/94444 – Astronaut Aug 17 '22 at 10:11
  • 1
    To specify a size limit: ```yaml - name: dshm emptyDir: medium: Memory sizeLimit: 1Gi ``` – Camille Louédoc Sep 30 '22 at 19:37
  • Thank you so much, it worked perfectly well! My configuration is Jenkins and an agent with Robot Framework on an Openshift cluster (in case it would of some help for someone else) – Daniele Gagliardi Feb 13 '23 at 18:12
-9
docker run --cap-add=SYS_ADMIN --shm-size 2G --name chrome chrome-hd

to run container locally where

--shm-size 2G

is used to tweak shm available size.

  • 3
    Please re-read the question. I already use --shm-size to run locally. This is a question about kubectl configuration – posit labs Jan 19 '18 at 18:30