Interview questions and model answers
"Why should a swarm have an odd number of managers?"
Raft needs a majority to commit changes. With 3 managers you can lose 1; with 4 you still can only lose 1 because quorum becomes 3 — the extra manager adds cost and failure risk without adding tolerance. I'd run 3 (or 5 for large clusters), spread across availability zones, and drain them of application workloads.
"What happens if the swarm loses quorum?"
Existing tasks keep running and published ports keep serving, but the cluster can't change state: no deploys, scaling, or rescheduling of failed tasks. I'd try to bring managers back; if they're permanently lost, run docker swarm init --force-new-cluster on a surviving manager to rebuild from its state, then promote new managers. Regular backups of /var/lib/docker/swarm make worst cases recoverable.
"Explain the routing mesh."
When a service publishes a port, Swarm opens it on every node through the ingress overlay network, and IPVS load-balances connections to healthy tasks on any node. An external load balancer can therefore target all nodes. The costs are an extra hop and loss of the client source IP; when that matters I publish in host mode, usually with a global edge proxy.
"How does Swarm handle secrets, and how do you rotate one?"
Secrets are encrypted in the Raft log, delivered over mutual TLS only to nodes running tasks that need them, and mounted as in-memory files under /run/secrets. They're immutable, so to rotate I create a new versioned secret and service update --secret-rm old --secret-add source=new,target=same-name, which rolls the tasks, then delete the old secret.
"How do you do a zero-downtime update in Swarm?"
Define a healthcheck so new tasks must be healthy before they count, use update_config with parallelism 1, a delay, order: start-first, and failure_action: rollback with a monitor window. Make sure the app handles SIGTERM gracefully and there's spare capacity for the start-first surge.
"Containers on two nodes can't reach each other over an overlay. What do you check?"
That nodes can reach each other on TCP/UDP 7946 for gossip and UDP 4789 for VXLAN data — security groups commonly miss UDP. Then MTU (VXLAN overhead can break large packets), that both services are attached to the same overlay network, and DNS resolution of the service name from inside a container.
"Swarm or Kubernetes for a new platform?"
Kubernetes, in most cases: it has the ecosystem (operators, GitOps with Flux, service meshes, policy engines), richer scheduling, autoscaling, RBAC, and managed offerings like EKS. Swarm wins on simplicity for a small team running a few services on a handful of hosts. I'd also consider ECS if the team is AWS-only and wants minimal operations.