Giter VIP home page Giter VIP logo

springboot-mongo-microservice's Introduction

spring-boot-mongo-kubernetes-docker

This is a sample spring-boot application that talks to mongoDB for GET/POST REST APIs and deployed in Kubernetes cluster.

Prerequisites minikube kubectl docker maven

Set up a Spring Boot app If you want to run with Maven, execute:

./mvn package && java -jar target/spring-boot-mongo-docker-1.0.0.jar and go to http://localhost:8080/customer/ to see your persisted customers.

Dockerisation We need a container with jdk to run our springboot application. There are many images with jdk 8 publicly available already but just to get the end to end experience We will built a minimal container based on alpine linux with Jdk 8

docker build -t aritranag20/spring-boot-mongo-docker .

Then log into docker, with your credentials after signing up on docker.io,

docker login

Execute the following command to push image to docker registry.

docker push aritranag20/spring-boot-mongo-docker

Containerize It

If you want to run with Docker, execute:

./docker-compose up

Deploying on Kubernetes Now that we have image of our application available in the docker registry, we can deploy it in a kubernetes cluster. We will also set up a node for mongoDB to be used as backend by our application.

Start local kubernetes cluster with the following command:

minikube start

We can then launch dashboard for the cluster:

minikube dashboard

Next create deployment of our application in the cluster.

kubectl create -f deployment.yml

We can see description of the service with

kubectl describe service spring-boot-mongo-docker

Now get the exact address of the service with

minikube service spring-boot-mongo-docker

which will launch browser and point to the endpoint. For e.g. in my case,

curl http://192.168.99.101:30864/user => [{"id":"58bcd7ad5908010005cce257","firstName":"Arun","lastName":null,"email":null,"address":{"street1":null,"street2":null,"town":null,"postcode":null,"state":null}}]

Summary Congratulations! You’ve just created a Docker container for a Spring Boot app with MongoDB and hosted the app in Kubernets! Spring Boot apps run on port 8080 inside the container by default and we mapped that to the same port on the pods which is load balanced across multiple replicas of the service and can be assessed by getting the NodePort from kubectl describe service spring-boot-mongo-docker command.

Optional Finally to stop your local kubernetes cluster:

minikube stop

springboot-mongo-microservice's People

Contributors

tharangar avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

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.