gyj0825 / k8s-word-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kubernetes Words Demo

Words is the demo project on k8s.

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:

Deploy Using a Kubernetes Manifest

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.

Apply the manifest using kubectl:

kubectl apply -f kube-deployment.yml

Now browse to http:// and you will see the same site.

Check the services are up, and you should see output like this:

$ kubectl get svc
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
words-api    ClusterIP      172.31.0.65      <none>        8080/TCP         4s
words-db     ClusterIP      172.31.0.243     <none>        5432/TCP         4s
words-web    LoadBalancer   172.31.0.58      192.168.0.9   80:30220/TCP     3s

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
words-api-9787944d6-f544j    1/1     Running   0          6s
words-api-9787944d6-fdczp    1/1     Running   0          6s
words-api-9787944d6-q4rdc    1/1     Running   0          6s
words-api-9787944d6-qqzb5    1/1     Running   0          6s
words-api-9787944d6-vbcn4    1/1     Running   0          6s
words-db-cc96d879d-fmzqk     1/1     Running   0          6s
words-web-69dbfc57cb-rlprp   1/1     Running   0          6s

Then browse to http:// to see the site. Each time you refresh the page, you'll see a different sentence generated by the API calls.

About


Languages

Language:Java 21.6%Language:HTML 20.0%Language:CSS 19.7%Language:Go 17.2%Language:JavaScript 16.0%Language:Dockerfile 5.6%