I am learning Docker and I did a simple exercise:
when I send HTTP request to BOTH machines I get correct reply.
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.
What is the idea behind Swarm clustering? Is Kubernetes different?
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 Docker swarm ingress/network mesh
You do this through the command line with:
$ docker service create \
--name <SERVICE-NAME> \
--publish published=8080,target=80 \
<IMAGE>
Then all your nodes will receive traffic on the published port and will get forwarded to the containers.
In the case above, from an external load balancer, you would could forward traffic to either port 80
(container exposed port) or port 8080
(published)
Kubernetes is very similar but not quite the same. Services are exposed externally through a LoadBalancer or NodePort. 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 192.168.99.100:80
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.