This is an example REST API and test built in Spring Boot.
Provide an example of how to deploy a Java REST api to Google Kubernetes Engine.
Most requirements are optional, but links are provided below.
Gradle 4(Optional, you can use the 'gradlew' or 'gradlew.bat' files instead)
This guide assumes a basic understanding of building REST services with Spring Boot. For a quick introduction, see Spring's Building a RESTful Web Service
This guide also assumes you have built a Kubernetes cluster similiar to Janus GKE Infrastructure
Build:
gradle build
Test:
gradle test
Run:
gradle bootRun
View:
Open your browser to localhost:8080/greetings
Build artifact:
gradle build
(If you haven't already)
Build Docker container:
docker build . --tag greeting-service
Run Docker container:
docker run greeting-service
View:
Open your browser to localhost:8080/greetings
More info on pushing a Docker container to Google's Container Registry
Tag:
docker tag greeting-service us.gcr.io/[PROJECT-ID]/greeting-service:1.0
Push:
gcloud docker -- push us.gcr.io/[PROJECT-ID]/greeting-service:1.0
Confirm:
gcloud container images list-tags us.gcr.io/[PROJECT-ID]/greeting-service
Run Application:
kubectl run greeting-service --image=gcr.io/[PROJECT-ID]/greeting-service:1.0 --port 8080
Expose through a load balancer:
kubectl expose deployment greeting-service --type="LoadBalancer"
Inspect:
kubectl get service greeting-service
Find the external IP from the above command (may take a few minutes) and then open your browser to
http://[EXTERNAL-IP]:8080/greetings
kubectl delete service greeting-service
Andrew Bell
homepage: www.recursivechaos.com
email: andrew@recursivechaos.com
twitter: @recursive_chaos