Deploying Application Wordsmith used in Dockercon EU 17

Wondering what this app is all about?

It was a demo app showcased at DockerCon Europe 2017 in Copenhagen.

  • Let's deploy another application called wordsmith
  • Wordsmith has 3 components:
    • a web frontend
    • an API backend
    • a database
  • We have built images for these components, and pushed them on the Docker Hub
  • We want to deploy all 3 components on Kubernetes
  • We want to be able to connect to the web frontend with our browser
  • Here are the names of the images that we've prepared:
    • jpetazzo/wordsmith-web:latest for the web frontend
    • jpetazzo/wordsmith-words:latest for the API
    • jpetazzo/wordsmith-db:latest for the database
  • Here are all the network flows in the app:
    • the web frontend listens on port 80
    • the web frontend connects to the API at the address http://words:8080
    • the API backend listens on port 8080
    • the API connects to the database with the connection string pgsql://db:5432
    • the database listens on port 5432
  • After deploying and connecting everything together, open the web frontend
  • This is what we should see:

(You will probably see a different sentence, though.)

  • Yes, there is some repetition in that sentence; that's OK for now
  • If you see empty LEGO bricks, something's wrong …
  • If we reload that page, we get the same sentence
  • And that sentence repeats the same adjective and noun anyway
  • Can we do better?
  • Yes, if we scale up the API backend!
  • Try to scale up the API backend and see what happens

First, we need to create deployments for all three components:

kubectl create deployment db --image=jpetazzo/wordsmith-db
kubectl create deployment web --image=jpetazzo/wordsmith-web
kubectl create deployment words --image=jpetazzo/wordsmith-words

Note: We need to use these exact names, because these names will be used for the service that we will create and their DNS entries as well. To put it differently: If our code connects to words then the service should be named words and the deployment should also be named words (unless we want to write our own service YAML manifest by hand; but we won't do that yet).

Then, we need to create the services for these deployments:

kubectl expose deployment db --port=5432
kubectl expose deployment web --port=80 --type=NodePort
kubectl expose deployment words --port=8080

Find out the node port allocated to web:

kubectl get service web
web    NodePort   <none>        80:31001/TCP   23m

Open it in your browser in this case http://hostip:31001

If you hit “reload”, you should always see the same sentence, however.

Finally, scale up the API:

kubectl scale deployment words --replicas=9

If you hit “reload”, you should now see different sentences each time.

Now we need to clean everything up.

Let's delete the deployments create.

kubectl delete deployment words web db
deployment.apps "words" deleted
deployment.apps "web" deleted
deployment.apps "db" deleted

Let's delete the services used to enable the ports

kubectl delete service words web db
service "words" deleted
service "web" deleted
service "db" deleted