How to run systemctl in a pod

5/22/2019

Getting access denied error while running the systemctl command in a pod.

Whenever try to start any service, for example, MySQL or tomcat server in a pod, it gives access denied error.

Is there any way by which I can run systemctl within a pod.

-- Suneha
kubernetes

2 Answers

5/22/2019

This is a problem related to Docker, not Kubernetes. According to the page Run multiple services in a container in docker docs:

It is generally recommended that you separate areas of concern by using one service per container

However if you really want to use a process manager, you can try supervisord, which allows you to use supervisorctl commands, similar to systemctl. The page above explains how to do that:

Here is an example Dockerfile using this approach, that assumes the pre-written supervisord.conf, my_first_process, and my_second_process files all exist in the same directory as your Dockerfile.

FROM ubuntu:latest
RUN apt-get update && apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY my_first_process my_first_process
COPY my_second_process my_second_process
CMD ["/usr/bin/supervisord"]
-- victortv
Source: StackOverflow

5/23/2019

That's a rather short question. The 'systemctl' command does try to talk to the systemd daemon which is not running in a pod by default (it could however). Running multiple services is yet another question about service management. It both cases it could help to use a tool like the docker-systemctl-replacement overwriting /usr/bin/systemctl and registering it as the init-CMD of the container.

-- Guido U. Draheim
Source: StackOverflow