Wordsmith is the demo project shown at DockerCon EU 2017, where Docker announced that support for Kubernetes was coming to the Docker platform.
The demo app runs across three containers:
-
db - a Postgres database which stores words
-
words - a Java REST API which serves words read from the database
-
web - a Go web application which calls the API and builds words into sentences:
The only requirement to build and run the app from source is Docker. Clone this repo and use Docker Compose to build all the images:
cd k8s-wordsmith-demo
docker-compose build
Or you can pull pre-built images from Docker Hub using
docker-compose pull
.
The latest version of Docker for Mac has Kubernetes built-in.
Docker lets you use the simple Docker Compose file format to deploy complex applications to Kubernetes. You can deploy the wordsmith app to the local Kubernetes cluster using docker-compose.yml.
First use docker version
to check whether Docker is running with Kubernetes or Docker Swarm as the orchestrator - Docker for Mac supports both orchestrators at the same time:
docker version -f '{{ .Client.Orchestrator }}'
You can switch orchestrators with the
DOCKER_ORCHESTRATOR
environment variable, setting it tokubernetes
orswarm
.
Deploy the app to Kubernetes as a stack using the compose file:
export DOCKER_ORCHESTRATOR=kubernetes
docker stack deploy wordsmith -c docker-compose.yml
Docker for Mac includes the kubectl command line, so you can work directly with the Kube cluster. Check the services are up, and you should see output like this:
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
db ClusterIP None <none> 55555/TCP 2m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 38d
web LoadBalancer 10.107.215.211 <pending> 8080:30220/TCP 2m
words ClusterIP None <none> 55555/TCP 2m
Check the pods are running, and you should see one pod each for the database and web components, and five pods for the words API - which is specified as the replica count in the compose file:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
db-8678676c79-h2d99 1/1 Running 0 1m
web-5d6bfbbd8b-6zbl8 1/1 Running 0 1m
words-858f6678-6c8kk 1/1 Running 0 1m
words-858f6678-7bqbv 1/1 Running 0 1m
words-858f6678-fjdws 1/1 Running 0 1m
words-858f6678-rrr8c 1/1 Running 0 1m
words-858f6678-x9zqh 1/1 Running 0 1m
Then browse to http://localhost:8080 to see the site. Each time you refresh the page, you'll see a different sentence generated by the API calls.
You can deploy the same app to Kubernetes using the Kubernetes manifest. That describes the same application in terms of Kubernetes deployments, services and pod specifications.
First remove the Kubernetes stack:
docker stack rm wordsmith
Alternatively You can leave the Docker stack deployment running, and create a second deployment in a new Kubernetes namespace.
Now apply the manifest using kubectl
:
kubectl apply --validate=true --filename ./kube-deployment.yaml
or:
kubectl apply --validate=true --filename https://github.com/patrickmslatteryvt/k8s-wordsmith-demo/raw/master/kube-deployment.yaml
Now browse to http://localhost:8081 and you will see the same site.
To do a rolling update to the Vermont theme:
kubectl apply --validate=true --filename https://github.com/patrickmslatteryvt/k8s-wordsmith-demo/raw/demo1/kube-deployment.yaml
Check the rollout history of the deployments:
$ kubectl --namespace=demos-words rollout history deployment
deployments "db"
REVISION CHANGE-CAUSE
11 <none>
12 <none>
deployments "web"
REVISION CHANGE-CAUSE
11 <none>
12 <none>
deployments "words"
REVISION CHANGE-CAUSE
11 <none>
12 <none>
Roll back the deployments to the Danish theme:
kubectl --namespace=demos-words rollout undo deployment/{db,words,web} --to-revision=11
deployment "db" rolled back
deployment "words" rolled back
deployment "web" rolled back
To remove the deployment:
kubectl delete --filename ./kube-deployment.yaml
or:
kubectl delete --filename https://github.com/patrickmslatteryvt/k8s-wordsmith-demo/raw/master/kube-deployment.yaml