<p>When I ssh directly inside my pod, and run the following on the command line: <code>curl -v --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" https://kubernetes.default.svc.cluster.local/apis/batch/v1/watch/namespaces/kludge/jobs/api-job-12</code> it works and returns all the updates for the specified job (<code>api-job-12</code>) in the form of a stream.</p>

<p>However, when I'm inside my application level code, I can't get the API to stream the response (the request times out with no response at all). I'm working inside a PHP(Laravel) environment and I'm using Guzzle for my http client. </p>

<p>Here's my code:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>        $token = file_get_contents('/var/run/secrets/kubernetes.io/serviceaccount/token');

        $client =  new Client([
            'headers' =&gt; [
                'Authorization' =&gt; "Bearer {$token}"
            ]
        ]);

        $response = $client-&gt;get(
            'https://kubernetes.default.svc/apis/batch/v1/watch/namespaces/kludge/jobs/api-job-12',
            [
                'verify' =&gt; '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
                'stream' =&gt; true
            ]
        );

        dd($response-&gt;getBody()-&gt;getContents());</code></pre>
</div>
</div>
</p>

<p>When I dump <code>$response-&gt;getBody()</code> I get the following:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>^ GuzzleHttp\Psr7\Stream {#338
  -stream: stream resource @21
    crypto: array:4 [
      "protocol" =&gt; "TLSv1.2"
      "cipher_name" =&gt; "ECDHE-RSA-AES128-GCM-SHA256"
      "cipher_bits" =&gt; 128
      "cipher_version" =&gt; "TLSv1.2"
    ]
    timed_out: false
    blocked: true
    eof: false
    wrapper_data: array:4 [
      0 =&gt; "HTTP/1.1 200 OK"
      1 =&gt; "Content-Type: application/json"
      2 =&gt; "Date: Sun, 01 Mar 2020 20:15:33 GMT"
      3 =&gt; "Connection: close"
    ]
    wrapper_type: "http"
    stream_type: "tcp_socket/ssl"
    mode: "r"
    unread_bytes: 0
    seekable: false
    uri: "https://kubernetes.default.svc/apis/batch/v1/watch/namespaces/kludge/jobs/api-job-12"
    options: array:2 [
      "http" =&gt; array:5 [
        "method" =&gt; "GET"
        "header" =&gt; """
          Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrbHVkZ2UiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoiZGVmYXVsdC10b2tlbi14ZjhsciIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiZDA5ZjZiZTAtM2UyOS00NWU3LWI3ZjgtOGE1YWI0OGZjNDJiIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OmtsdWRnZTpkZWZhdWx0In0.eAtABzj-SimmTGNCQXkmtVHFPYoxiZWV7ET5tYK3OIa6-Ea6WA3cy7cMmObRILTc26cLU4YX8YovhzoNAV8RkteKAVGv2HNvaeOXD_AKkYilX618SUMEfat-zsnXYUego24gNLPtPFRefRyEwAnxf6E61DDwSWWlyptKiggcnl8GHrlY_14oumOsFpsjsRTc807DsuZGn1jCU1Dw2DPhSz457a-afXb0jggzorYNzDtfG6rBTKYctPI4wfh30y9iwjPLTU5L5B-8mYqWn9lgOs2Z9XkFu1GRUD19j6bgAnzoyfVCY8uJp9FGi1Ega84n_MsC6cXmS7K7_QiyBtFR-Q
          User-Agent: GuzzleHttp/6.5.1 curl/7.64.0 PHP/7.2.28
          Host: kubernetes.default.svc
          Content-Length: 0
          Connection: close
          """
        "protocol_version" =&gt; "1.1"
        "ignore_errors" =&gt; true
        "follow_location" =&gt; 0
      ]
      "ssl" =&gt; array:4 [
        "cafile" =&gt; "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"</code></pre>
</div>
</div>
</p>

<p>It does appear to be a stream object, but the object says it has no bytes to read and that it is not seekable. Does anyone have any ideas as to how I can get a stream response using PHP here?</p>

<p>Here's the Kubernetes API endpoint that I'm calling:
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#watch-47" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#watch-47</a></p>

<p>Have you tried to actually read from this stream? Private fields can be confusing, so I would suggest to try <a href="http://docs.guzzlephp.org/en/stable/request-options.html#stream" rel="nofollow noreferrer">the public interface</a> and see what you get:</p>

<pre><code>$body = $response-&gt;getBody();
while (!$body-&gt;eof()) {
    echo $body-&gt;read(1024);
}
</code></pre>
