DEV Community

Cover image for Docker Swarm vs Kubernetes
Dharmil Chhadva
Dharmil Chhadva

Posted on

Docker Swarm vs Kubernetes

Automating the deployment pipeline is becoming increasingly important in today's fast-evolving world, where applications are broken down into microservices. This is where Docker and Kubernetes come into play.

Before we dive deep into Docker and Kubernetes, let's first understand what containers are.


What are containers?

A container packages the application code and its dependencies in one unit, which then can be executed on any infrastructure. It's lightweight and includes everything required to run the app, such as code, runtime environment, system libraries, and external dependencies. The core aim is to quickly deploy the application, which executes the same regardless of the underlying architecture.

Containers eliminate the "works on my machine" 🤣 phrase.

Huge production bug, but developer says works on my machine


Now that we understand containers let's move on to Docker Swarm.

What is Docker Swarm?

Docker Swarm is a container orchestration tool that allows you to manage and deploy applications using containerization. It's an open -source and popular as it is quick to set up and easy to use. Docker Swarm is called swarm mode and is a native Docker mode. Swarm mode allows DevOps engineers to create a cluster of Docker nodes and deploy services to run on these nodes. This cluster is called Swarm.

A swarm cluster consists of manager nodes, which manage the cluster and worker nodes, which are instructed to run tasks by the manager nodes.

Swarm Architecture

Swarm Architecture


Image Credit: Docker Swarm vs Kubernetes: A Practical Comparison

Pros of Docker Swarm:

  • Familiarity as swarm mode is a part of Docker.
  • Easy to install and set up.
  • Has its own Swarm API.
  • Smooth integration with Docker Compose and Docker CLI.
  • Intelligent node selection for picking optimal nodes.
  • Built-in load balancing feature, eliminating the need to define load balancer files manually.
  • Roll back to the previous version of the service in case of hazardous events such as failures.
  • Fault tolerance, wherein swarm automatically checks for node failures and replaces them with new ones.
  • It can scale up and down as per demand.

Cons of Docker Swarm:

  • Limited customizations and extensions.
  • Less functionality and lesser automation capabilities compared to Kubernetes.

Swarm mode CLI commands:

  • swarm init: Initialize a swarm. The Docker Engine this command targets becomes a manager in the newly created single-node Swarm.

Example:

> docker swarm init --advertise-addr 192.168.99.121

Swarm initialized: current node (bvz81updecsj6wjz393c09vti) is now a manager.

To add a worker to this Swarm, run the following command:

    docker swarm join --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx 172.17.0.2:2377

To add a manager to this Swarm, run 'docker swarm join-token manager' and follow the instructions.
Enter fullscreen mode Exit fullscreen mode
  • Swarm join: Join a node to a swarm. The node joins as a manager node or worker node based on the token you pass with the --token flag. If you pass a manager token, the node joins as a manager. If you pass a worker token, the node joins as a worker.

Example:

> docker swarm join --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 192.168.99.121:2377
This node joined a swarm as a manager.
Enter fullscreen mode Exit fullscreen mode

What is Kubernetes?

Kubernetes is also a container orchestration tool which allows you to deploy and manage applications. It's open-source, portable, and highly configurable. These features make it an optimal choice for deploying complex applications. A cluster in Kubernetes consists of worker nodes, which are managed by Kubernetes master. The master controls, monitors and manages all the resources in the cluster.

Kubernetes Architecture

Swarm Architecture


Image Credit: Docker Swarm vs Kubernetes: A Practical Comparison

The above diagram depicts the components involved in Kubernetes.

  • Controller Plane: It manages the operation of the Kubernetes cluster.

    • Kube API Server: Facilitates external communication with the cluster.
    • Etcd: Stores configuration data and cluster state in a key-value store.
    • Scheduler: Allocates pod placement based on resource needs and availability.
    • Kube Controller Manager: Maintains desired component states.
  • Kubernetes Node: Executes control plane assigned tasks, including:

    • Kubelet: Manages containers and their lifecycle.
    • Pod: Smallest component of the cluster. Represents a running process instance.

Execution Workflow:

  1. External clients interact with the cluster via kubectl commands.
  2. The controller plane delegates tasks to Kubernetes nodes.
  3. Nodes create pods for container execution.
  4. External users access deployed apps through a load balancer.

Pros of Kubernetes

  • Wide range of functionalities such as service discovery, load balancing, storage orchestration, self-healing, horizontal scalability, automated rollout and rollbacks and batch execution.
  • Open-source with a highly active community.
  • Allows you to store and manage configuration data and secrets securely.
  • Allows flexible management of resources when deploying an application.
  • Is highly extensible through plugins.
  • Interact with Kubernetes components via its API.

Cons of Kubernetes

  • Learning Kubernetes and managing its master requires specialized knowledge due to its steep learning curve.
  • Frequent updates from the open-source community need careful patching to prevent workload disruptions.
  • Kubernetes is too heavy for solo developers who are handling simple apps with occasional deployments.
  • Teams require tools like kubectl CLI, CI/CD workflows, and DevOps practices to manage access, identity, governance, and security.

Docker Swarm Vs Kubernetes

Feature Docker Swarm Kubernetes
Set up Easy with docker command Setting up a Kubernetes cluster manually can be complicated.
Container support Works only with Docker containers Works with containerd, Docker, etc.
Networking Basic Advanced
Learning Curve Easy to get started Steep curve
Complexity Simple & lightweight Complicated & heavyweight
Load Balancing Automatic Manual
CLIs Comes when installing Docker Need to install kubectl CLI
Scalability No automatic scaling Automatic Scaling
Security Only TLS support Supports SSL/TLS, RBAC & secret management

Conclusion

In conclusion, while Docker Swarm and Kubernetes serve as container orchestration tools, they have distinct characteristics and functionalities.

Docker swarm offers easy setup and simplicity, making it ideal for smaller projects with straightforward deployment needs. However, it lacks the advanced features and scalability of Kubernetes.

On the other hand, Kubernetes provides a comprehensive set of features for managing complex applications at scale. Although it has a steep learning curve and requires specialized knowledge, Kubernetes offers extensive functionality, including advanced networking, automated scaling, and robust security features.

Ultimately, the choice between Docker Swarm and Kubernetes depends on the specific requirements and complexity of the project. Docker Swarm may suffice for simpler deployments, while Kubernetes is better suited for larger, more intricate applications that demand advanced orchestration capabilities.


References

Docker Swarm vs. Kubernetes: A Comparison
Docker Swarm vs Kubernetes: A Practical Comparison


Note: This article is a part of the curriculum in the DevOps course. My student ID is C0884179.


Check Out My Previous Articles

Changing the MAC Address using Python
Writing a Network Scanner using Python
Man In The Middle Attack (MITM) Part 1 — ARP Spoofing
Man In The Middle Attack (MITM) Part 2 — Packet Sniffer

Top comments (0)