<p>Inside a kubenertes environment, there is an API Server which we can call to watch a ressource. We can call this API Server thanks a HTTP request (or WebSocket but this is not related to my question) and I wonder how the API server deals to never terminate this request and keep to notify the client of any change about the ressource.</p>
<p>EDIT : I mean the HTTP protocol is a request/response protocol, I know with HTTP2 we can keep a same TCP connection open to perform multiple requests but it sill has to be a request/response nature. So how the watch mechanism works with this request/response protocol ?</p>
<hr />
<p>From key</p>
<p>The key is chunked header.</p>
<p>you can see a header while requesting to kube API server
<code>Transfer-Encoding: chunked</code></p>
<p><a href="https://en.wikipedia.org/wiki/Chunked_transfer_encoding" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Chunked_transfer_encoding</a></p>
<p>In doc, server can send payload continuously using this header.</p>
<p>In kubernetes, you can check it also</p>
<p>curl -v 127.0.0.1:8001/apis/apps/v1/watch/namespaces/&lt;mycase :)&gt; &gt;</p>
<pre><code>GET /apis/apps/v1/watch/namespaces/&lt;mycase :)&gt; HTTP/1.1 
&gt; Host: 127.0.0.1:8001
&gt; User-Agent: curl/7.64.1
&gt; Accept: */*
&gt;
&lt; HTTP/1.1 200 OK
&lt; Cache-Control: no-cache, private
&lt; Content-Type: application/json
&lt; Date: Wed, 07 Jul 2021 03:47:33 GMT
&lt; Transfer-Encoding: chunked 
</code></pre>

Kizux
<p>Kubernetes stores all its resources inside etcd, a key-value store, and etcd provides a watch functionality that the Kubernetes API exploits.</p>

<p>You can read about the etcd watch specifics <a href="https://github.com/etcd-io/etcd/blob/master/clientv3/watch.go" rel="nofollow noreferrer">here</a>.</p>
