Giter Site home page Giter Site logo

dockersamples / wordsmith Goto Github PK

View Code? Open in Web Editor NEW
250.0 15.0 450.0 411 KB

Sample project with Docker containers running under Kubernetes

License: Apache License 2.0

Go 15.24% JavaScript 13.18% HTML 15.76% CSS 21.30% Java 24.24% Dockerfile 10.28%
docker kubernetes example sample demo swarm docker-compose

wordsmith's Introduction

Wordsmith App

Wordsmith is the demo project originally shown at DockerCon EU 2017 and 2018.

The demo app runs across three containers:

  • api - a Java REST API which serves words read from the database
  • web - a Go web application that calls the API and builds words into sentences
  • db - a Postgres database that stores words

Architecture

Architecture diagram

Build and run in Docker Compose

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. You can use the new V2 Compose with docker compose or the classic docker-compose CLI:

docker compose up --build

Or you can pull pre-built images from Docker Hub using docker compose pull.

Deploy using Kubernetes manifests

You can deploy the same app to Kubernetes using the Kustomize configuration. It will define all of the necessary Deployment and Service objects and a ConfigMap to provide the database schema.

Apply the manifest using kubectl while at the root of the project:

kubectl apply -k .

Once the pods are running, browse to http://localhost:8080 and you will see the site.

Docker Desktop includes Kubernetes and the kubectl command line, so you can work directly with the 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:

kubectl get pods
NAME                   READY     STATUS    RESTARTS   AGE
db-8678676c79-h2d99    1/1       Running   0          1m
web-5d6bfbbd8b-6zbl8   1/1       Running   0          1m
api-858f6678-6c8kk     1/1       Running   0          1m
api-858f6678-7bqbv     1/1       Running   0          1m
api-858f6678-fjdws     1/1       Running   0          1m
api-858f6678-rrr8c     1/1       Running   0          1m
api-858f6678-x9zqh     1/1       Running   0          1m

wordsmith's People

Contributors

alexandreroman avatar bretfisher avatar dependabot[bot] avatar estesp avatar johnharris85 avatar manomarks avatar mikesir87 avatar otherguy avatar sixeyed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wordsmith's Issues

Cleanup Hub repos and images

For the below repos, complete these tasks:

  • Enable CVE scanning in Docker Hub
  • Add descriptions and basic readmes
  • Remove outdated image tags (or add GHA to push them)

https://hub.docker.com/r/dockersamples/wordsmith-api
https://hub.docker.com/r/dockersamples/wordsmith-web

Delete these unused/duplicate repos:

Maintain these repo's for the years of old example blogs, but document in their Hub readme that they are deprectaed.

Web service responses cached by Safari

Under Safari Technology Preview Release 61 (Safari 12.0, WebKit 13606.1.25.1), noun and adjective APIs are only called once each, and so the same words are displayed. I suspect this is because the responses from the web server do not contain any cache control headers, and so Safari reuses the first response.

image

kube-deployment.yml not working: no matches for kind "Deployment" in version "apps/v1beta1"

Following https://www.docker.com/docker-desktop/getting-started-for-windows in step 5 it says to save the contents of this file to kube-deployment.yml and then run:

kubectl apply -f kube-deployment.yml

Unfortunately it errors as follows:

service/db created
service/words created
service/web created
unable to recognize "kube-deployment.yml": no matches for kind "Deployment" in version "apps/v1beta1"
unable to recognize "kube-deployment.yml": no matches for kind "Deployment" in version "apps/v1beta1"
unable to recognize "kube-deployment.yml": no matches for kind "Deployment" in version "apps/v1beta1"

Is the YAML file in this repo wrong, or is the Docker website getting started guide using it wrongly?

Environment

  • Docker Desktop 2.3.0.5 (48029), 'about' says Kubernetes v1.16.5
  • installed on Win 10 Enterprise 1909
kubectl version
Client Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.6-beta.0", GitCommit:"e7f962ba86f4ce7033828210ca3556393c377bcc", GitTreeState:"clean", BuildDate:"2020-01-15T08:26:26Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.6-beta.0", GitCommit:"e7f962ba86f4ce7033828210ca3556393c377bcc", GitTreeState:"clean", BuildDate:"2020-01-15T08:18:29Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"linux/amd64"}

Unable to display words, page crashes on refresh.

I am able to get the kube yml to deploy, but when I navigate to localhost:8081, I get a page with the proper layout, but no words. Console error screenshot attached. If I refresh that page, it no longer connects.

I'm running this on a local tectonic cluster. I've relaunched the cluster, deleted my docker images and reapplied the kubenetes yml.

screen shot 2018-05-11 at 2 18 12 pm

Service 'words' failed to build

Getting below error on docker-compose:

docker-compose -f C:\www\demoapp\docker-compose.yml build

Step 12/15 : RUN apk add --no-cache openjdk8-jre="8.161.12-r0" && rm usr/lib/libgif.so.7.0.0 usr/lib/libtasn1.so.6.5.5
 ---> Running in 05906a76108f
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  openjdk8-jre-8.171.11-r0:
    breaks: world[openjdk8-jre=8.161.12-r0]
    satisfies:
           openjdk8-jre-8.171.11-r0[openjdk8-jre]
ERROR: Service 'words' failed to build: The command '/bin/sh -c apk add --no-cache openjdk8-jre="8.161.12-r0" && rm usr/lib/libgif.so.7.0.0 usr/lib/libtasn1.so.6.5.5' returned a non-zero code: 1

Rename wordsmith repo

  • rename k8s-wordsmith-demo to just wordsmith
  • create docker hub repos for the two apps
  • update docs and compose yaml to reflect new names
  • search for any other areas that might have these names (docker docs)

Kubectl apply is not exposing the app on localhost

Downloaded and apply this command to run the app: kubectl apply -f kube-deployment.yml

kubectl get svc
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
db           ClusterIP      None             <none>        5432/TCP         22m
kubernetes   ClusterIP      10.96.0.1        <none>        443/TCP          56m
web          LoadBalancer   10.104.155.249   <pending>     8081:31850/TCP   22m
words        ClusterIP      None             <none>        8080/TCP         22m

I cannot access the app from localhost:8081 or localhost. I tried with docker-compose command with swarm and it's working fine but not with kubernetes orchestrator.

Please advice!

Tried below command:

kubectl exec web-5c7b6669f7-9fb9j -c web -- wget -O - localhost

Result:

<!DOCTYPE html>
<html lang="en" ng-app="lab">
<head>
  <meta charset="utf-8">
  <title>dockercon EU 17</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="logo"><img src="images/logo.svg" /></div>

<div class="sentence" ng-controller="LabCtrl">
  <div class="line line1 slide-in">
  <span class="result adjective slide-in">
    <span class="word slide-in" ng-bind="adjective1.word"></span>
    <span class="hostname" ng-bind="adjective1.hostname"></span>
  </span>
  <span class="result noun slide-in">
    <span class="word" ng-bind="noun1.word"></span>
    <span class="hostname" ng-bind="noun1.hostname"></span>
  </span>
  </div>
  <div class="line line2 slide-in">
  <span class="result verb slide-in">
    <span class="word" ng-bind="verb.word"></span>
    <span class="hostname" ng-bind="verb.hostname"></span>
  </span>
  </div>
  <div class="line line3 slide-in">
  <span class="result adjective slide-in">
    <span class="word" ng-bind="adjective2.word"></span>
    <span class="hostname" ng-bind="adjective2.hostname"></span>
  </span>
  <span class="result noun slide-in">
    <span class="word" ng-bind="noun2.word"></span>
    <span class="hostname" ng-bind="noun2.hostname"></span>
  </span>
  </div>
</div>

<div class="footer"><img src="images/homes.png" /></div>
</body>

<script src="angular.min.js"></script>
<script src="app.js"></script>
</html>
Connecting to localhost (127.0.0.1:80)
-                    100% |*******************************|  1398   0:00:00 ETA

clusterIp

I'm trying to follow this sample and when I apply the kube-deployment.yml the cli spits out

spec.clusterIP: Invalid value: "None": field is immutable

Service 'words' failed to build

➜ k8s-wordsmith-demo git:(master) ✗ docker version
Client:
Version: 18.03.0-ce-rc1
API version: 1.37
Go version: go1.9.4
Git commit: c160c73
Built: Thu Feb 22 02:34:03 2018
OS/Arch: darwin/amd64
Experimental: true
Orchestrator: kubernetes

Server:
Engine:
Version: 18.03.0-ce-rc1
API version: 1.37 (minimum version 1.12)
Go version: go1.9.4
Git commit: c160c73
Built: Thu Feb 22 02:42:37 2018
OS/Arch: linux/amd64
Experimental: true

How to reproduce:

➜ k8s-wordsmith-demo git:(master) ✗ docker-compose build

Error:

Executing java-common-0.1-r0.trigger
OK: 81 MiB in 50 packages
rm: can't remove 'usr/lib/libtasn1.so.6.5.4': No such file or directory
ERROR: Service 'words' failed to build: The command '/bin/sh -c apk add --no-cache openjdk8-jre="8.151.12-r0" && rm usr/lib/libgif.so.7.0.0 usr/lib/libtasn1.so.6.5.4' returned a non-zero code: 1
➜ k8s-wordsmith-demo git:(master) ✗

errors during building 'web' image

# command-line-arguments
/usr/local/go/pkg/tool/linux_arm64/link: running gcc failed: exec: "gcc": executable file not found in $PATH

Occurs when building this webimage image

This seems to be another base image that needs to be changed.

arm64 images for DockerMac (M1 Apple Silicon)

This could be great demo for k8s on Apple Silicon!
Could you please provide arm64 builds on dockerhub?
Otherwise default kubernetes installations pull the amd64 images which don't work on M1 Macs with Docker Mac

Rename words folder to api

It feels a little odd to have the API directory to be named words. Instead, we should rename it to api. Update any GHA workflows, compose files, etc. for the change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.