janslee / homework_k8s

Sample Java application converted to K8s with Helm Chart

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

K8s

Java application

Target application might be found here:

https://github.com/stantonk/java-docker-example.git

Requirements

  1. docker
  2. docker-machine
  3. helm
  4. kubectl
  5. minikube

Workflow

  1. login to dockerhub docker login
  2. change .env file and set DOCKERHUB_OWNER to username (the same as in previous login command)
  3. java.sh - build java base image, upload to dockerhub
  4. build.sh - build application image, upload to dockerhub
  5. deploy.sh - spin up kubernetes on minikube, configure RBAC and initialize helm
  6. change something in java code
  7. build.sh - re-build images, re-upload to dockerhub
  8. refresh.sh - refresh helm chart
  9. cleanup.sh - clean everything up (excluding dockerhub images)

Resulting service will be available via NodePort at:

http:// < minikube ip > :30303/api/tweets

You may want to open it with:

minikube service demo-example-http --profile demo --namespace default

Or access with port-forward:

POD=$(kubectl get pods -n default --selector app=example \
    -o template --template '{{range .items}}{{.metadata.name}} {{.status.phase}}{{"\n"}}{{end}}' \
    | grep Running | head -1 | cut -f1 -d' ')

kubectl port-forward -n default ${POD} 8081:8080

Or via Ingress Controller:

echo "$(minikube ip --profile demo) jexmpl.example.com" | sudo tee -a /etc/hosts

Then open:

http://jexmpl.example.com/api/tweets

You may try ngrok as the last chance option

FAQ

  1. Can we do a HA of a database? Any way to keep the data persistent when pods are recreated?

    We have stateless frontend, but stateful backend. Of course we can have HA configuration in such configuration.

    We can set following option to helm to enable HA:

    --set mysql.persistence.enabled=true
    
  2. Add CI to the deployment process.

    Just combine shell scripts from workflow above

  3. Split your deployment into prd/qa/dev environment.

    Tweak .env file

  4. Please suggest a monitoring solutions for your system. How would you notify an admin that the resources are scarce?

    A lot of option, you may want to start from prometheus-operator from coreos

Copyright

You may use my work or its parts as you wish, but only with proper credits to me like this:

Viacheslav - avoidik@gmail.com

About

Sample Java application converted to K8s with Helm Chart


Languages

Language:Shell 55.0%Language:Dockerfile 24.7%Language:Smarty 20.3%