Docker Swarm Mode vs. Kubernetes: Key Facts You Need to Know
Docker Swarm Mode and Kubernetes are two of the most popular tools for container clustering and orchestration, despite their divergent philosophies and capabilities. Since both platforms are quite distinct, experience with one generally...
Docker Swarm Mode and Kubernetes are two of the most popular tools for container clustering and orchestration, despite their divergent philosophies and capabilities. Since both platforms are quite distinct, experience with one generally won’t be helpful with the other beyond the common experience of building Docker images, which both use. This makes your initial choice of which to work with even more important. But what exactly can they do, and how do they stack up against each other?
What Are They?
Docker is an open-source project for automated deployment of Linux applications inside self-sufficient “namespaces” called containers. Docker Swarm mode natively manages a cluster of Docker Engines called a swarm, available only with Docker 1.12. Prior to Swarm mode’s introduction, Docker Swarm and Swarmkit were both available but did not integrate into the Docker Engine API and CLI commands, they were installed and run separately. Swarm previously needed an external key-value store and did not support service discovery or load balancing. Swarm mode is not available to users with a version of Docker older than the 1.12 release, though users running 1.12 who choose to deploy Swarm instead of Swarm mode are still supported.
Swarm mode allows developers and administrators to create and manage a virtual system, a “swarm,” that is composed of one or more Docker nodes. Every host in a given cluster runs a Swarm agent controlled by the Swarm manager(s), which schedules and orchestrates containers. The new features of Swarm mode include load balancing, service discovery, scaling, rolling updates, a secure data plane, and routing mesh.
Kubernetes is an open-source cluster manager for containers. It was originally designed by Google, who based its development on years of experience working with Linux containers. Kubernetes clusters are made up of several components: pods, labels, services, and replication controllers.
Pods are the basic unit of scheduling in Kubernetes. They are a group of containers intended to be deployed and scheduled together, coordinating to execute a particular task. If you were to deploy a single container, it would be deployed as a single pod.
Labels represent user-defined attributes that are attached to pods.
A service is a unit that acts as a basic load balancer and ambassador for other containers. Services are a way to interface with a group of containers; they allow you to simplify your container designs since they group together a logical collection of pods based on your labels.
Replication controllers are a framework for defining horizontally scaled pods. These replication controllers are responsible for handling replicated pods. If containers go down, replication controllers will start up another container and kill that container when the first one comes back online.
Since Swarm mode is a part of your Docker engine, there is no additional installation necessary after you install Docker 1.12. To deploy Docker Swarm, use a fixed IP address and assign it to a network interface available to the host operating system. You now have everything you need to create a swarm.
Kubernetes installation is more involved, but can be simple if you use the right tools. Installing Kubernetes with kubeadm (a tool that is part of Kubernetes 1.4) is ideal for integrating with existing orchestration systems or bare metal environments. Weaveworks has contributed to kubeadm with the goal of making Kubernetes easier to install. The advantage of Kubernetes is that you have more ultimate control over the configuration of the software. Furthermore, most common platforms now have documentation available on how to set up Kubernetes.
Docker Swarm mode and Kubernetes are both feature-rich platforms that provide you with a rich panoply of features. For example, both solutions are compatible with Weave Net, our networking tool for connecting containers. Each have engaging communities for like minded enthusiasts to learn and collaborate. Both support persistent data storage via Kubernetes’ Persistent Volumes and Docker Swarm mode’s volume plugins. Because Swarm mode is part of Docker, you also have easy access to Docker’s native tools. A direct interface with tools, such as Docker Compose, isn’t available with Kubernetes, which works on top of Docker instead of with it.
Furthermore, the deployment of containers is handled differently between Swarm mode and Kubernetes. The winner here really depends on whether you prefer working with the native Docker tool set. Docker deployments are typically done through Docker Compose or the Docker command line. In Kubernetes, container deployment is usually done via kubectl, which is difficult to use because of Kubernetes’ complex and layered APIs. This, however, makes Kubernetes deployment more expressive.
Both Docker and Kubernetes claim to support clusters of up to 1,000 nodes with no performance degradation; Docker also claims to support up to 30,000 containers with no dip in performance. According to Kubernetes, 99 percent of its API calls return within one second, and 99 percent of Kubernetes pods and containers will open within five seconds.
Thanks to Swarm mode, the performance gap between Kubernetes and Docker is closing. Before Swarm mode was even introduced, a March 2016 study by Jeff Nickoloff evaluated the performance of both Docker Swarm and Kubernetes while running 30,000 containers on 1,000 node clusters. Nickoloff found that Swarm was roughly five times faster than Kubernetes when initializing a new container. But, he was impressed by the Kubernetes replication controller, which allowed him to create 3,000 container replicas in under 155 seconds. It should also be noted that this study was comparing setup time and not application performance.
Ultimately, both Docker Swarm and Kubernetes are well-built tools, and the answer of which one to choose depends on what you want to do with it. The great appeal of Swarm mode – that it is a part of your Docker engine – can also be its downfall if you want support for customized scheduling. Meanwhile, if you can tolerate Kubernetes’ abstractions and reliance on independent services, it can be a powerful tool to bypass some of the limitations of Docker. For those with simple needs seeking a single solution that works “out of the box,” Docker is your tool. If you need more nuanced control over your containers, choose Kubernetes. As long as you are able to accomplish what you set out to do, there is no wrong answer.
Weaveworks’ software works with both Docker and Kubernetes. Sign up for Weave Cloud today to see how it integrates with the container orchestrator of your choice.