<p>I have a kubernetes setup in which one is <code>master</code> node and two <code>worker</code> nodes. After the deployment, which is a <code>daemonset</code>, it starts pods on both the <code>worker</code> nodes. These pods contain 2 containers. These containers have a python script running in them. The python scripts runs normally but at a certain point, after some time, it needs to send a <code>shutdown</code> command to the host. I can directly issue command <code>shutdown -h now</code> but this will run on the container not on the host and gives below error:</p>

<pre><code>Failed to connect to bus: No such file or directory
Failed to talk to init daemon.
</code></pre>

<p>To resolve this, I can get the <code>ip address</code> of the host and then I can ssh into it and then run the command to safely shutdown the host.</p>

<p>But is there any other way I can issue command to the host in kubernetes/dockers.?</p>

<p>You can access your cluster using kube api.</p>

<p><a href="https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/</a></p>

<blockquote>
  <p>Accessing the API from a Pod When accessing the API from a pod,
  locating and authenticating to the apiserver are somewhat different.</p>
  
  <p>The recommended way to locate the apiserver within the pod is with the
  kubernetes.default.svc DNS name, which resolves to a Service IP which
  in turn will be routed to an apiserver.</p>
  
  <p>The recommended way to authenticate to the apiserver is with a service
  account credential. By kube-system, a pod is associated with a service
  account, and a credential (token) for that service account is placed
  into the filesystem tree of each container in that pod, at
  /var/run/secrets/kubernetes.io/serviceaccount/token.</p>
</blockquote>

<p>Draining the node you can use this</p>

<blockquote>
  <p>The Eviction API</p>
</blockquote>

<p><a href="https://kubernetes.io/docs/tasks/administer-cluster/safely-drain-node/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/administer-cluster/safely-drain-node/</a></p>

<p>But i dont really sure about on pod can drain own node. Workaround can be controlling other pod from different node.</p>
