I have a Dockerfile which copies an installer to the container and the default command specified in Dockerfile is /usr/sbin/init, since I need to run certain services. Once the container is created via kubectl create -f server-rc.yml command, I am running a kubectl exec command in interactive mode to run that installer and provide inputs automatically via node.js script, the command goes like this kubectl exec $container -i -t -- bash -c "node install.js"(this runs the installer and automatically provides inputs via stdin), which starts my custom service on the pods.
Everything is fine till now. Now let's says out of 2 pods, one pod dies and a new one spawns up. Now, how can I ensure that these interactive commands that I had initially run on the pods gets run on the newly generated pods as well? I am not sure if using command and args in the spec would work since they all work in non interactive mode. Any thoughts on how to get this resolved would be appreciated.
Edit:
Dockerfile(partial code):
FROM centos:7
ENV container docker
RUN yum -y update; yum clean all
VOLUME [ “/sys/fs/cgroup” ]
RUN yum -y install nodejs npm && npm install progress
RUN mkdir -p /tmp
COPY ./install.js /tmp
COPY ./test.bin /tmp/
CMD ["/usr/sbin/init"]The node.js script opens up test.bin via child_process.spawn and then listens on process.stdout.on and based on what is received on stdout, provides inputs via process.stdin.write.
Thanks.
I am not sure what you mean by interactive. If this means the script needs human interaction, you cannot automate this (since you need somebody who does that).
Since Kubernetes Pods can die anytime you should make the script non-interactive and extend the entrypoint/command, so it does the node install.js before starting the actual server. One example is the official Docker image for MySQL, which defines an entrypoint and does some preconfiguration before actually starting the server.
It's hard to be more precise, since we don't have the Dockerfile or the install.js script.
Edit It would be even better if the install.js would run inside the Dockerfile, since this would speed up the start and make the server code immutable.