...

/

Comparison with Docker Swarm

Comparison with Docker Swarm

Compare Kubernetes Deployments with Docker Swarm stacks.

Kubernetes Deployments compared to Docker Swarm stacks

If you have already used Docker Swarm, the logic behind Kubernetes Deployments should be familiar. Both serve the same purpose and can be used to deploy new applications or update those that are already running inside a cluster. In both cases, we can easily deploy new releases without any downtime (when application architecture permits that).

Comparing definitions

Let’s look at the way we define objects in both Kubernetes and Docker Swarm.

Kubernetes

An example of a Kubernetes Deployment and Service definition is as follows:

Press + to interact
apiVersion: apps/v1
kind: Deployment
metadata:
name: go-demo-2-db
spec:
selector:
matchLabels:
type: db
service: go-demo-2
strategy:
type: Recreate
template:
metadata:
labels:
type: db
service: go-demo-2
vendor: MongoLabs
spec:
containers:
- name: db
image: mongo:3.3
ports:
- containerPort: 27017
---
apiVersion: v1
kind: Service
metadata:
name: go-demo-2-db
spec:
ports:
- port: 27017
selector:
type: db
service: go-demo-2
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: go-demo-2-api
spec:
replicas: 3
selector:
matchLabels:
type: api
service: go-demo-2
template:
metadata:
labels:
type: api
service: go-demo-2
language: go
spec:
containers:
- name: api
image: vfarcic/go-demo-2
env:
- name: DB
value: go-demo-2-db
readinessProbe:
httpGet:
path: /demo/hello
port: 8080
periodSeconds: 1
livenessProbe:
httpGet:
path: /demo/hello
port: 8080
---
apiVersion: v1
kind: Service
metadata:
name: go-demo-2-api
spec:
type: NodePort
ports:
- port: 8080
selector:
type: api
service: go-demo-2

Docker Swarm

An equivalent Docker Swarm stack definition is as follows:

Press + to interact
version: "3"
services:
api:
image: vfarcic/go-demo-2
environment:
- DB=db
ports:
- 8080
deploy:
replicas: 3
db:
image: mongo:3.3

Both definitions provide, more or less, the same functionality.

It is evident that a Kubernetes Deployment requires a much longer definition with more complex syntax. It is worth noting that Swarm’s equivalent to readinessProbe and livenessProbe is not present in the stack because it is defined as a HEALTHCHECK inside the Dockerfile. Still, even if we remove them, a Kubernetes Deployment remains longer and more complicated. ...