简体   繁体   中英

How to enable swap/swapfile on Google container optimized OS on GCE?

Using the cos-stable container optimized OS on GCE. Micro instance so ram is pretty sparse. Tried to enable swap to prevent locking due to OOM during docker pulls, but can't get it to work.

I realize most folders are stateless, so I put the swapfile under home:

sudo fallocate -l 1G /home/user/swapfile

sudo chmod 600 /home/user/swapfile

sudo mkswap /home/user/swapfile results in:
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) no label, UUID=6e965805-2ab9-450f-aed6-577e74089dbf

But sudo swapon /home/user/swapfile gives the error:
swapon: /home/user/swapfile: swapon failed: Invalid argument

Any ideas how to enable swap on cos?

Thanks

Disk based swap is disabled in the COS image. You can enable disk based swap with

sysctl vm.disk_based_swap=1

I have the following in my cloud-init:

bootcmd:
- sysctl vm.disk_based_swap=1
- fallocate -l 1G /var/swapfile
- chmod 600 /var/swapfile
- mkswap /var/swapfile
- swapon /var/swapfile

Swap is not supported in container optimized OS

Swap would effectively destroy much of the behavioral isolation Google offers between containers.

Guaranteed pods should never require swap. Burstable pods should have their requests met without requiring swap. BestEffort pods have no guarantee.

I highly suggest you use a bigger instance as a f1-micro only has 600MB of RAM and you still need to run the OS on the instance it addition with your containers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM