<p>I want to drain node on shutdown and uncordon on start, I wrote below unit file but i am getting error (Openshift 3.11 and Kubernetes 1.11.0)</p>
<pre><code>[Unit]
Description=Drain Node at Shutdown
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
ExecStart=/bin/sleep 60 &amp;&amp; kubectl uncordon $HOSTNAME
ExecStop=kubectl drain $HOSTNAME --ignore-daemonsets --force --grace-period=30  &amp;&amp; /bin/sleep 60
[Install]
WantedBy=halt.target reboot.target shutdown.target
</code></pre>
<p>its giving me error</p>
<pre><code>error: no configuration has been provided
</code></pre>
<p>I set Environment variable but still no success</p>
<pre><code>[Service]
Environment=&quot;KUBECONFIG=$HOME/.kube/config&quot;
</code></pre>

<p>Following systemd unit is working, in ExecStop %H should be use for HOSTNAME</p>
<pre><code>[Unit]
Description=Drain Node at Shutdown
After=network.target glusterd.service
[Service]
Type=oneshot
Environment=&quot;KUBECONFIG=/root/.kube/config&quot;
ExecStart=/bin/true
ExecStop=/usr/bin/kubectl drain %H --ignore-daemonsets --force --grace-period=30 --delete-local-data
TimeoutStopSec=200
# This service shall be considered active after start
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
</code></pre>
