Use Kubernetes pod to run script on host node

7/19/2019

I have a Daemonset that places a pod onto all of my cluster's nodes. That pod looks for a set of conditions. When they are found it is supposed to execute a bash script on its node.

Currently my pod that I apply as a daemon set mounts the directory with the bash script. I am able to detect the conditions that I am looking for. When the conditions are detected I execute the bash script but it ends up running in my alpine container inside my pod and not on the host node.

As as simple example of what is not working for me (in spec):

command: ["/bin/sh"]
args: ["-c", "source /mounted_dir/my_node_script.sh"]

I want to execute the bash script on the NODE the pod is running on, not within the container/pod. How can this be accomplished?

-- Aoradon
kubernetes
kubernetes-pod

1 Answer

11/7/2019

Actually a command run inside a pod is run on the host. It's a container (Docker), not a virtual machine.

If your actual problem is that you want to do something, which a normal container isn't allowed to, you can run a pod in privileged mode or configure whatever you exactly need.

-- Ajinkya Betwar
Source: StackOverflow