<p>I created a simple API in python using a Flask.</p>
<p>Api is used to watch movies and it works as a proxy, that is:</p>
<p>Api gets a link from the user with page that contains mp4. Using a link, it downloads mp4 with a web request from user link page and returns mp4 to the user, but these mp4 (links) are assigned to the IP, so in order for the user to watch the movie everything has to go through the API, the API must make another query and return the query to the user.</p>
<p>This is what a part of my API looks like, which is responsible for making requests to watch the movie.</p>
<pre><code>@WatchBp.route(&quot;/stream&quot;, methods=[&quot;GET&quot;])
def stream():
   print(request.headers)
   try:
       link = html.unescape(request.args.get(&quot;link&quot;))
       origin = html.unescape(request.args.get(&quot;origin&quot;))
       referer = html.unescape(request.args.get(&quot;referer&quot;))
       r = requests.get(link, headers={&quot;Range&quot;: request.headers[&quot;Range&quot;], &quot;referer&quot;: referer, &quot;origin&quot;: origin}, stream=True)
       res = Response(r.iter_content(chunk_size=10 * 1024),mimetype=r.headers[&quot;Content-Type&quot;],direct_passthrough=True,status=r.status_code)
       res.headers[&quot;Content-Range&quot;] = r.headers[&quot;Content-Range&quot;]
       res.headers[&quot;Accept-Ranges&quot;] = 'bytes'
       res.headers[&quot;Content-Length&quot;] = r.headers[&quot;Content-Length&quot;]
       return res
   except:
       pass
   return ('',501)

</code></pre>
<p>The entire Api stands on the Digitalocean using kubernetes and it using digitalocean loadbalancer.</p>
<p>Containers that contain api use the docker image tiangolo / uwsgi-nginx-flask: python3.8 .</p>
<p><strong>Currently, the application is based on 1 kubernetes node</strong></p>
<p><strong>Now there are some more users and I would like to add a second node.</strong></p>
<p><strong>But the second node is the second computer, and if the link to mp4 is taken from node 1 and the next loadbalancer query redirects to node 2, the application will fail to download mp4 because it will not be the same ip.</strong></p>
<p>The configuration of my application using kubernetes uses Ingress, ingress feeds are hooked up to the Loadbalancer, and Ingress feeds redirect traffic to my API.</p>
<p><strong>Now the question is, is it possible for the user who watches the movie to always be redirected to the node from which mp4 was downloaded?
Thanks for any help.</strong></p>

somedisplayname21
<p>i am not sure how actually it's working moving traffic to the node.</p>
<p>As your traffic or request ideally want to go to the same POD each time.</p>
<p>A sticky session might be helpful here from Nginx ingress</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-ingress
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/affinity: &quot;cookie&quot;
    nginx.ingress.kubernetes.io/session-cookie-name: &quot;hello-cookie&quot;
    nginx.ingress.kubernetes.io/session-cookie-expires: &quot;172800&quot;
    nginx.ingress.kubernetes.io/session-cookie-max-age: &quot;172800&quot;
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
    nginx.ingress.kubernetes.io/affinity-mode: persistent
    nginx.ingress.kubernetes.io/session-cookie-hash: sha1
spec:
  rules:
  - host: DOMAIN.NAME
    http:
      paths:
      - path: /
        backend:
          serviceName: hello-service
          servicePort: hello-port
</code></pre>
<p>you can read more at : <a href="https://zhimin-wen.medium.com/sticky-sessions-in-kubernetes-56eb0e8f257d" rel="nofollow noreferrer">https://zhimin-wen.medium.com/sticky-sessions-in-kubernetes-56eb0e8f257d</a></p>
