<p>I have a server which is running inside of a kubernetes pod.
Its log output can be retrieved using "kubectl logs".</p>

<p>The application goes through some start up before it is ready to process incoming messages.
It indicates its readiness through a log message.</p>

<p>The "kubectl logs" command is not available from within the pod. I think it would be insecure to even try to install it.</p>

<p><strong>Is there a way of either:</strong></p>

<ul>
<li><strong>getting the log from within the container?</strong> or</li>
<li><strong>running a readiness probe that is executed outside of the container?</strong>
(rather than as a <em>docker exec</em>)</li>
</ul>

<p>Here are some options I've considered:</p>

<ul>
<li>Redirecting the output to a log file loses it from "Kubectl log"</li>
<li><p>Teeing it to a log file avoids that limitation but creates an unnecessary duplicate log.</p></li>
<li><p>stdout and stderr of the application are anonymous pipes (to kubernetes) so eavesdropping on /proc/1/fd/1 or /proc/1/fd/2 will not work.</p></li>
</ul>

<p>A better option may be to use the <a href="https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/" rel="nofollow noreferrer">http API</a>. For example <a href="https://stackoverflow.com/questions/54907546/kubernetes-how-to-get-pod-logs-within-container">this question</a> </p>

<pre><code>kubectl proxy --port=8080
</code></pre>

<p>And from within the container:</p>

<pre><code>curl -XGET http://127.0.0.1:8080/api
</code></pre>

<p>However I get an error:</p>

<pre><code>Starting to serve on 127.0.0.1:8080
I0121 17:05:38.928590   49105 log.go:172] http: Accept error: accept tcp 127.0.0.1:8080: accept4: too many open files; retrying in 5ms
2020/01/21 17:05:38 http: proxy error: dial tcp 127.0.0.1:8080: socket: too many open files
</code></pre>

<p>Does anyone have a solution or a better idea?</p>

Bruce Adams
<p>You can actually do what you want. Create a kubernetes "serviceaccount" object with permissions just to do what you want, use the account for your health check pod, and just run kubectl logs as you described. You install kubectl, but limit the permissions avaialable to it.</p>

<p>However, there's a reason you don't find examples of that- its not a great way of building this thing. Is there really no way that you can do a health check endpoint in your app? That is so much more convenient for your purposes.</p>

<p>Finally, if the answer to that really is "NO", could you have your app write a ready file? Instead of <code>print "READY"</code> do <code>touch /app/readyfile</code>. then your health check can just check if that file exists. (to make this work, you would have to create a volume and mount it at /app in both your app container and the health check container so they can both see the generated file)</p>
