<p>I have a mssql pod that I need to use the <a href="https://github.com/free/sql_exporter" rel="nofollow noreferrer">sql_exporter</a> to export its metrics.
I was able to set up this whole thing manually fine:</p>
<ol>
<li>download the binary</li>
<li>install the package</li>
<li>run ./sql_exporter on the pod to start listening on port for metrics</li>
</ol>
<p>I tried to automate this using <code>kubectl exec -it ...</code> and was able to do step 1 and 2. When I try to do step 3 with <code>kubectl exec -it &quot;$mssql_pod_name&quot; -- bash -c ./sql_exporter</code> the script just hangs and I understand as the server is just going to be listening forever, but this stops the rest of my installation scripts.</p>
<pre><code>I0722 21:26:54.299112     435 main.go:52] Starting SQL exporter (version=0.5, branch=master, revision=fc5ed07ee38c5b90bab285392c43edfe32d271c5) (go=go1.11.3, user=root@f24ba5099571, date=20190114-09:24:06)
I0722 21:26:54.299534     435 config.go:18] Loading configuration from sql_exporter.yml
I0722 21:26:54.300102     435 config.go:131] Loaded collector &quot;mssql_standard&quot; from mssql_standard.collector.yml
I0722 21:26:54.300207     435 main.go:67] Listening on :9399
&lt;nothing else, never ends&gt;
</code></pre>
<p>Any tips on just silencing this and let it run in the background (I cannot ctrl-c as that will stop the port-listening). Or is there a better way to automate plugin install upon pod deployment? Thank you</p>

bZhang
<h5>To answer your question:</h5>
<p>This <a href="https://stackoverflow.com/a/49245303/609290">answer</a> should help you. You should (!?) be able to use <code>./sql_exporter &amp;</code> to run the process in the background (when <strong>not</strong> using <code>--stdin --tty</code>). If that doesn't work, you can try <code>nohup</code> as described by the same answer.</p>
<h5>To recommend a better approach:</h5>
<p>Using <code>kubectl exec</code> is not a good way to program a Kubernetes cluster.</p>
<p><code>kubectl exec</code> is best used for debugging rather than deploying solutions to a cluster.</p>
<p>I assume someone has created a Kubernetes Deployment (or similar) for Microsoft SQL Server. You now want to complement that Deployment with the exporter.</p>
<p>You have options:</p>
<ol>
<li>Augment the existing Deployment and add the <code>sql_exporter</code> as a sidecar (another container) in the Pod that includes the Microsoft SQL Server container. The exporter accesses the SQL Server via <code>localhost</code>. This is a common pattern when deploying functionality that complements an application (e.g. logging, monitoring)</li>
<li>Create a new Deployment (or similar) for the <code>sql_exporter</code> and run it as a standalone Service. Configure it scrape one|more Microsoft SQL Server instances.</li>
</ol>
<p>Both these approaches:</p>
<ul>
<li>take more work but they're &quot;more Kubernetes&quot; solutions and provide better repeatability|auditability etc.</li>
<li>require that you create a <a href="https://hub.docker.com/r/githubfree/sql_exporter" rel="nofollow noreferrer">container for <code>sql_exporter</code></a> <strike>(although I assume the exporter's authors already provide this)</strike>.</li>
</ul>
