Keep Moving Forward | X-Team Magazine

Docker vs Kubernetes: Not What It Seems

Written by Thomas De Moor | Nov 19, 2019 5:00:00 AM

Let me come straight out of the gates by saying that there is no such thing as "Docker vs Kubernetes". Both technologies are not competitors of one another and you don't have to choose between either Docker or Kubernetes. In fact, the opposite is true. Both technologies work well together and many large companies use them together to deploy, run, and manage their containers.

You see, Docker is a container platform while Kubernetes is a container orchestration platform. Both serve different purposes. While Docker allows you to spin up, run, and maintain containers, Kubernetes allows you to coordinate, schedule, and monitor those containers efficiently (among other use cases - Kubernetes is complex and can do many different things).

The reason why you frequently hear about "Docker vs Kubernetes" is because Docker has its own orchestration platform, called Docker Swarm. So the real comparison should be "Docker Swarm vs Kubernetes".

But before you ask yourself whether you should use Docker Swarm or Kubernetes, it's worth taking a few steps back to understand what a container actually does, why you should use containers over traditional virtual machines, why container orchestration exists, and when it's worth using it.

What is a Container?

A container allows a developer to package up their app, along with the config files, binaries, and libraries required to run the app, and separate it from the infrastructure that it's running on.

This is extremely useful, because such a container can now run in whichever environment it's placed, whether that's the developer's MacBook, the QA rig, or the production data center. If it works without issues in one environment, the developer can be certain it will run without issues in other environments too (most importantly, in a production environment).

Containers vs Virtual Machines

You'd be correct in thinking that a container sounds a lot like a virtual machine (VM). However, containers have a few advantages over VMs that make them the preferable option for building and deploying apps.

Firstly, a container is lightweight while a VM isn't. Each instance of a VM requires its own OS plus all the dependencies and the libraries that are required for the app to run. All this software can consume several gigabytes of storage and memory.

Containers vs VMs

Containers, however, can all run on the same Linux kernel and share libraries between themselves. This makes them much more lightweight and faster to launch. Perfect for microservice architectures and CI/CD.

Of course, this doesn't make VMs obsolete, because you'll likely be running your containers within the VMs provided by Amazon, Google, or Microsoft.

Why Container Orchestration?

If you have only a few containers, you might not have to worry about creating and running containers manually. However, once you start having a few dozen, you'll want to automate the process of creating, running, and maintaining containers. That's where container orchestration comes in.

Container orchestration software allows the operations team to automate the deployment of containers, determine the best use of compute resources across containers, understand how to best scale containers, and create entry points to the containerized services.

Kubernetes is currently the most popular container orchestration platform. It was created by Google and released in 2014, when it was also made open-source (contrary to Docker Enterprise, which was recently acquired by Mirantis).

Kubernetes vs Docker Swarm

It should be fairly obvious, if you're using Docker as your container platform (and you likely are), that Docker Swarm is tightly integrated into the Docker ecosystem.

Docker Swarm clusters together multiple Docker hosts and presents the same Docker API. This means that you can integrate with any third-party tool that works with a single Docker host.

Docker Swarm also isn't as complex as Kubernetes. It uses the Docker CLI, which means that it's not so difficult to learn if you're already familiar with Docker itself.

However, Kubernetes' complexity also means that it's more feature-rich. It has its own API, client, and YAML definitions (which you use to create the Kubernetes manifest). It has built-in tools for logging and monitoring and a reliable dashboard that's useful for anyone who doesn't have a technical background.

Docker Swarm doesn't have built-in monitoring and logging, nor does it have a reliable dashboard. You'll need to integrate third-party tools such as ELK, Reimann, or Portainer for the above.

Additionally, Kubernetes is much better for automatically scaling container up or down depending on your requirements. You'll need to integrate Docker Swarm with a third-party tool such as StackStorm for it to auto-scale.

In Conclusion

Containers allow you to separate your apps from the infrastructure it's running on, making it much easier to test and scale them.

They're much more lightweight than virtual machines because they can run on the same operating system and can share libraries between themselves.

Once you have a few dozen containers, you'll want to automate the process of deploying, running, and maintaining your containers. This can be done with a container orchestration platform such as Kubernetes or Docker Swarm.

All in all, whether you use Docker Swarm or Kubernetes will depend on the number of containers you have. If you have a few dozen container, Docker Swarm might be the best option. However, if you have over a hundred containers or if you value features such as logging and monitoring or auto-scaling, Kubernetes will serve you much better.