<p>I am learning Docker and I did a simple exercise:</p>

<ul>
<li>prepared 2 machines </li>
<li>set up Leader and Worker on them </li>
<li>deployed 2 instances of simple web-app with stack command</li>
</ul>

<p>when I send HTTP request to BOTH machines I get correct reply.</p>

<p>That is strange for me. I thought only Leader node should handle requests because there is some load balancing in Swarm. I thought if some node failes Swarm should automatically redirect requests to another one and Leader node is where it happens. But looks like Swarm works in a different way.</p>

<p>What is the idea behind Swarm clustering?
Is Kubernetes different?</p>

MiamiBeach
<p>In Docker swarm the leader handles decisions on how to schedule the containers in your nodes and how to have them setup so that traffic is forwarded to them. However, the traffic doesn't go to the leader per se, but rather to the <a href="https://docs.docker.com/engine/swarm/ingress/" rel="nofollow noreferrer">Docker swarm ingress/network mesh</a></p>

<p>You do this through the command line with:</p>

<pre><code>$ docker service create \
  --name &lt;SERVICE-NAME&gt; \
  --publish published=8080,target=80 \
  &lt;IMAGE&gt;
</code></pre>

<p>Then all your nodes will receive traffic on the published port and will get forwarded to the containers.</p>

<p><a href="https://i.stack.imgur.com/rIOyQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rIOyQ.png" alt="swarm"></a></p>

<p>In the case above, from an external load balancer, you would could forward traffic to either port <code>80</code> (container exposed port) or port <code>8080</code> (published)</p>

<p>Kubernetes is very similar but not quite the same. <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Services</a> are exposed externally through a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer">LoadBalancer</a> or <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">NodePort</a>.  However, you can't get directly to the pod IP addresses from the outside because those are not seen on the outside, as opposed to <code>192.168.99.100:80</code> in the Docker swarm example above.  Also, the traffic in Kubernetes doesn't go through the master (except when you are making a call to the kube-apiserver), but directly to the nodes.</p>
