title: use of kubectl log in readiness probe
body: <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>