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:
apiVersion: apps/v1kind: Deploymentmetadata:name: go-demo-2-dbspec:selector:matchLabels:type: dbservice: go-demo-2strategy:type: Recreatetemplate:metadata:labels:type: dbservice: go-demo-2vendor: MongoLabsspec:containers:- name: dbimage: mongo:3.3ports:- containerPort: 27017---apiVersion: v1kind: Servicemetadata:name: go-demo-2-dbspec:ports:- port: 27017selector:type: dbservice: go-demo-2---apiVersion: apps/v1beta2kind: Deploymentmetadata:name: go-demo-2-apispec:replicas: 3selector:matchLabels:type: apiservice: go-demo-2template:metadata:labels:type: apiservice: go-demo-2language: gospec:containers:- name: apiimage: vfarcic/go-demo-2env:- name: DBvalue: go-demo-2-dbreadinessProbe:httpGet:path: /demo/helloport: 8080periodSeconds: 1livenessProbe:httpGet:path: /demo/helloport: 8080---apiVersion: v1kind: Servicemetadata:name: go-demo-2-apispec:type: NodePortports:- port: 8080selector:type: apiservice: go-demo-2
Docker Swarm
An equivalent Docker Swarm stack definition is as follows:
version: "3"services:api:image: vfarcic/go-demo-2environment:- DB=dbports:- 8080deploy:replicas: 3db: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. ...