The idea of packaging software in containers is changing how applications are delivered on the web. Customers and businesses now demand fast, scalable apps that can be continuously upgraded with close to 100% uptime. Tools like Docker are helping make this a reality.
The ability to whip up virtual ’containers‘ to run applications in a repeatable, predictable way is a powerful tool. But, deploying, scaling, and managing these containers is a difficult task. Today we‘re going to compare two of the most popular container management tools right now in 2017- Google Kubernetes and Docker Swarm – to see which one you should be using at your organization.
- Containers – A Better Way to Virtualize
- Why Do You Need a Container Orchestration Tool
- What is Docker Swarm?
- What is Google Kubernetes?
- Docker vs Kubernetes Comparison
- Which is Better?
- Which Should You Use?
- Finding the Right Developers
Containers – A Better Way To Virtualize
The traditional way to create a repeatable environment to run an application is with virtual machines. This allows you to have consistency all the way from development to production. While this works well, it is very computationally expensive. To run a single application you could need Gigabytes of RAM and a ton of processing power. That‘s because each virtual machine needs to run a full copy of the operating system, plus everything else needed to run an application.
Containers tackle the problem in a different way. A container holds all of an applications code, libraries, dependencies, and any other necessary configuration. This container can then be run as its own process on top of a machine using a tool such as Docker. You get the predictable environment of a virtual machine, but you don‘t need to run an entire operating system. In fact, when running containers using Docker, many containers all share an operating system kernel. This makes them orders of magnitude faster and more efficient than using virtual machines.
Check out our comparison of Docker and Vagrant (a tool for working with virtual machines) here for more info on the topic.
With Containers, you get benefits such as:
- DevOps and continuous delivery – easy to update a container, assess the results, then either roll the update to the rest of the containers or revert back to the old version
- Scalability – scale your application by simply adding more containers
- Replicate environments – create identical copies of a full application stack and configurations, so anyone can safely experiment in isolation
- Confidence in testing – know that your development and testing environments match your deployment environment
- High Availability – If one container fails, another replica can take over the work.
- Isolation – containers are completely isolated from each other, allowing you to simultaneously run development, test, and production versions of an application on the same server
- Performance – Efficient performance compared to Virtual Machines
Why Do You Need a Container Orchestration Tool?
Download Our Project Specification Template
Containers are awesome at packaging an application with its dependencies in a way that you can run anywhere easily. But, containers themselves can‘t do things like:
- Provisioning hosts
- Distribute containers across multiple servers
- Load balance between containers
- Scale up or scale down a cluster by adding or removing containers
- Reschedule failed containers
- Recovering when a server or node fails
- Connecting containers through an agreed interface
When building a scalable cloud application using containers, you need some way of managing the containers in the most efficient way possible. That‘s where container orchestration tools come into play. Google Kubernetes and Docker Swarm are both powerful tools to get your application running in a distributed, highly resilient environment while appearing as one application to anyone using it.
What is Docker Swarm?
Docker Swarm is the native clustering and container management tool for Docker. It’s been part of the core since version 1.12. It lets you manage a cluster of Docker nodes, and allows you to interact with them like a single system. It also optimizes your IT resources by scheduling containers to run on the most appropriate host, balancing container workloads and making sure containers are launched where there are enough resources. All of this is done while maintaining the performance levels you define.
Docker orchestration balances containerized application workloads, ensuring containers are launched on systems with adequate resources while maintaining necessary performance levels.
Docker Swarm focuses on:
- Simplicity and easy to use – it “just works”
- Resilient architecture – zero single-point-of-failure
- Secure by default
- Backward compatibility with other Docker tools
That last part is one of the coolest things about Docker Swarm. It‘s API is backward compatible with the existing Docker API. That means any containers or tools you were using with Docker (Docker CLI, Docker Compose, Krane…) will just work with Docker Swarm. Or, if you haven’t used Docker before, you only need to learn one set of tools for setting up your containers AND managing them.
What is Kubernetes?
Kubernetes is Google‘s take on container orchestration. It‘s open source and works with Docker containers. It‘s one of the most feature rich and powerful frameworks including things like:
- Automated container deployment and replication
- Online scaling up and down
- Load balancing across clusters and containers
- Rolling upgrades (more on this later)
- Automatic rescheduling of failed containers
- Exposing cluster resources to outside systems
It‘s based on the ideas Google itself uses to provide their search services to the world, so you know the technology is going to be excellent. It‘s so scalable that it was one of the key technologies underpinning the Pokemon Go launch in 2016. Considering that Pokemon Go was one of the most widely successful and played apps of all time, and the release had (relatively) few problems, you can see the potential Kubernetes has.
However, one of the most common user complaints is that Kubernetes has a steep learning curve and can be more difficult to use than Docker Swarm. This is true, as Kubernetes has a different command line interface, a different API, and different YAML definitions. That means if you want to use Kubernetes, you need to learn a whole new tool.
Kubernetes vs Docker Swarm – Comparison
Let‘s check out each of the containerization platforms to discover their strengths and weaknesses. Afterward, you‘ll hopefully have an idea of which
Setup and installation
Kubernetes takes a bit of work to get up and running. You‘ll have to manually configure a number of different components, like the Docker engine, etcd, and flannel. The installation process is different for each OS and for different providers. You‘ll also need to know a bunch of cluster configuration in advance, such as the number of nodes, IP addresses, and node roles.
If you aren‘t an expert, get ready for lots of problems and Googling before you are ready to go with Kubernetes!
Read How We Helped a Marketing Company to Build a Back-Office Custom Ads Dashboard
Docker Swarm, on the other hand, is built to be easy to learn and use. As of version 1.12, Swarm is part of the Docker core, so there is no setup required. It uses the Docker Command Line Interface (CLI), so you can just build your containers as you need. You don‘t need to plan out your clusters as you do with Kubernetes.
Ease of Use
Kubernetes is also more difficult to work with once you‘ve set it up. If you‘re running in on top of Docker, you‘ll need to know both the Docker CLI AND the Kubernetes CLI if you want to get anything done. It also requires its own YAML definitions for setup. Using Kubernetes as your containerization manager will require you to learn Docker (if you haven‘t already) AND all Kubernetes. Kubernetes is also just more complicated to work with than Docker Swarm.
The Docker Swarm API can be used just like you use other Docker tools such as Docker Compose. It shares the Docker CLI, meaning you can get a new container running with a single command. This is awesome because it‘s so easy to use, but it does have its drawbacks. If you want to perform some function that isn‘t supported by the Docker API, there isn‘t an easy way around it.
Docker Swarm and Kubernetes have comparable performance (as we’ll see below in the table). The main difference is in their architecture – the way the logically deal with solving the same problem. Docker continues its philosophy of simplicity here, which means it is faster for many applications. Kubernetes focuses more on guaranteeing certain performance levels and is designed to be able to handle more complex systems. This gives it an advantage when building larger applications for enterprises. Let’s take a look in more detail…
Here’s a table comparing all of the main features of each platform. Each subtopic is very intricate, so click on the links for more detailed guides or documentation.
|Scalability||Supports clusters with up to 1000 nodes. It comes with strong guarantees in a service level objectives, such as:
API responsiveness: 99% of all API calls return in less than 1s.
Pod startup time: 99% of pods and their containers (with pre-pulled images) start within 5s.
|Tested to support 1000 nodes and 30,000 containers. And, there was no noticeable difference between the startup time of the 1st or 30,000th node.|
|Availability||Highly Available. Pods are distributed across worker nodes. Failed nodes are automatically detected and managed to avoid downtime.||Highly Available. Containers are distributed across Swarm Nodes for redundancy and high availability. The Swarm Manager manages resources at scale, and are also replicated to ensure they are highly available. Tools such as Consul and ZooKeeper can help out if a Primary Swarm Manager fails.|
|Logging and Monitoring||Supports multiple types of monitoring services deployed in a cluster:||Mainly just supports monitoring with third party tools such as Reimann. Check this article out for more info.|
|Load Balancing||Kubernetes allows pods to be defined as a service. You can then set up a load balancer to access these services.||The swarm manager uses ingress load balancing to expose the services you want to make available externally to the swarm. It also uses internal load balancing. Check out the docs for more detailed info.|
|Auto-scaling||Excellent. Targets such as number-of-pods and CPU-utilization-per-pod are available directly through the API and more are on the way. All you need to do is set these targets and Kubernetes will automatically assign resources to maintain them.||Docker Swarm does not support auto-scaling, and there is no easy way to auto-scale with Docker Swarm at the moment. You can declare the number of tasks you want to run – and Swarm Manager will adapt to maintain this state when you scale up or down.|
|Rolling Upgrades/Rollback||Kubernetes handles updates progressively. Each container is updated one at a time, to make sure the service is available at all times. If anything goes wrong, a working version will be rolled back automatically.||Can apply updates to nodes incrementally. If anything should fail, you can easily roll back to the previous version of the service that worked.|
|Storage||APIs available to connect with storage backends like AWS. More powerful than what is available with Docker, but more complicated too. Uses the Volumes abstraction to allow containers to share data if they are in the same pod.||Swarm also has support for Volumes, which are used to manage data inside and between Docker Containers. Slightly less elegant and robust than the Kubernetes solution.|
|Networking||Kubernetes solves this problem very differently to Docker by default. Specifically, it aims at solving four main problems: container-to-container communications, Pod-to-Pod communications, Pod-to-Service communications, and External-to-Service communications. They state that they aim to create a “clean, backwards-compatible model where pods can be treated much like VMs or physical hosts from the perspectives of port allocation, naming, service discovery, load balancing, application configuration, and migration.“||Docker Engine can communicate between containers on a single host, but Docker Swarm is used to create overlay networks that span across multiple hosts in a cluster. Traffic between hosts is encrypted by default. You can also use a special ingress network that load balances between a service’s nodes.|
|Service Discovery||A DNS server is a strongly recommended cluster addon that watches the Kubernetes API and for new services and creates DNS records for each. These can then be found by Pods automatically.||Docker Swarm makes service discovery relatively simple. By default, containers are given their own virtual IP that acts as a front end for clients to reach the service. There’s also a DNS round-robin option if you want to use your own load balancer.|
|Performance||Kubernetes is has a more complex and flexible architecture than Docker and comes with stronger guarantees. These things slow the performance down.||Docker uses a simpler architecture so, in terms of sheer speed, it has an advantage. Also, this test showed that it was significantly faster than Kubernetes when scaled to this level. The complex architecture and strong service guarantees make Kubernetes slower.|
So Which One Is Better?
Like every software comparison, Docker Swarm vs Kubernetes doesn’t have a clear cut winner. It depends on what problem you are solving and your current experience. Both have their strengths and weaknesses.
Kubernetes is a complete package. The guys at Google are the best in the world at creating scalable cloud development tools, and Kubernetes is excellent. That’s why the Pokemon Team used it for their epic launch of Pokemon Go. They knew a lot of people were going to use the app, and they also knew it could turn into a worldwide viral hit. They chose Kubernetes as their containerization platform to do the job, and it was quite successful. The first few days Pokemon Go traffic was 50x the original estimation and 10x the worst case scenario estimate. Despite this, the team managed to scale up support quickly and there were only minor outages. That’s pretty incredible!
Docker Swarm, on the other hand, is built to just work. It’s fast, easy to install, uses familiar interfaces, works nicely with tools, and does a lot of things for you out of the box. The downside is that there is some limit on its functionality, and if you need something that isn’t supported by the Docker Command Line Interface, there’s no easy way to get it.
Which One Should You Use?
At the end of the day, Kubernetes and Docker Swarm perform similar functions. And, you can probably get most applications working on both using different approaches. There are also other container management platforms out there such as Mesos and Amazon ECS.
We’ve looked at the pros and cons of each, but if you still aren’t sure which one to go with, I would start with Docker Swarm. It provides you with everything you need to get started and it is probably going to be able to do anything you need. The only exception might be if you’re developing a more complex application with very high demands. Maybe the next Pokemon Go!
Finding The Right Developers
The right team of developers will know exactly which tools will suit your project. You need to make sure that the solution you choose is going get you results fast and allow for the right kind of growth in the future. DevTeamSpace has teams of developers with experience creating cloud-native applications using Docker, Kubernetes, and other awesome tools.
Go Spin Up Some Containers!
We’ve taken a look at the problems containers solve, why you might need a containerization platform, and what two of the most popular ones can offer you. Now all that’s left is to get started. Get started with Docker here, and get started with Google Kubernetes here.