We have a library that uses POSIX message queues to pass data between processes and requires having the msgqueue kernel parameter set to unlimited, otherwise the process will return an error too many open files
. Usually we view/set this using ulimit -q
and ulimit -q unlimited
, but for some Kubernetes containers we want to be able to set this directly via go code.
We have already confirmed that the pod spec allows changing mqueue settings (via securityContext for Kubernetes 1.14+) and that the specific container can adjust resource setting:
...
kind: Deployment
...
spec:
template:
spec:
securityContext:
sysctls:
- name: fs.mqueue.msg_max
value: "10000"
- name: fs.mqueue.msgsize_max
value: "102400"
containers:
- name: testing
securityContext:
capabilities:
add:
- SYS_RESOURCE
...
Without those settings even ulimit -q unlimited
would get an error:
bash: ulimit: POSIX message queues: cannot modify limit: Operation not permitted
But how would we use syscall.Setrlimit to adjust the limit value from our code?