Skip to content

Latest commit

 

History

History
105 lines (84 loc) · 3.75 KB

README.md

File metadata and controls

105 lines (84 loc) · 3.75 KB

Spring Boot Deploy to PWS and K8s demo

This project was generated using Spring initializr

This demo demonstrates how to quickly get a spring boot application up and running, and how to deploy to Cloud Native platforms like Pivotal Web Services (PWS) and K8s.

Disclaimer

  • This project just shows how to push an app quickly. It doesn't follow best practices such as Testing, CI/CD, and proper build configurations. But, hopefully it can show how easy it is to push apps to production with the right Cloud Native frameworks and tools!

Running locally

$ ./gradlew bootRun

To test:

$ curl http://localhost:8080/api/v1/hello

Deploying to PWS

Pre-requisites

Steps

  1. Build the application by running:
$ ./gradlew assemble
  1. Login using cf cli. This is an example for PWS:
$ cf login -a https://api.run.pivotal.io
  1. Ensure that manifest.yml is populated

  2. Push!

$ cf push
  1. By default, the cf cli will use the manifest.yml in the current directory for deployment. The included default manifest requests a random route for the app. Watch your terminal output to see the URL at which you can access the app.

  2. Done! Query the appropriate URL.

Deploying to K8s

Pre-requisites

  • K8s cluster provisioned. See Tanzu Kubernetes Grid, GKE, or EKS
  • kubectl installed, and configured with context pointing to K8s cluster
  • Local Docker installed
  • DockerHub account, to push and host container images. This can be replaced with private container registries (such as Harbor), which is beyond the scope of this demo
  1. Update the following files, and replace yourUser/yourRepoNameHere with the name of your own repository. Note that in subsequent steps, replace the same placeholder with the proper value.
  2. Run a gradle sync to sync dependencies
  3. Build the image using:
$ ./gradlew bootBuildImage
  1. Run the image locally:
$ docker run -it --rm -p 8080:8080 yourUser/yourRepoNameHere:latest
  1. Test that the application is running by making a request and checking the response:
$ curl http://localhost:8080/api/v1/hello
  1. Push to DockerHub:
$ docker push yourUser/yourRepoNameHere:latest
  1. Push to K8s:
$ kubectl apply -f k8s-manifest.yml
  1. Wait for the LoadBalancer public IP to come up, by watching the External IP for the demo-app-spring service. Note: this was tested on GKE, but different K8s platforms may have different implementations/requirements for LoadBalancers.
$ kubectl get services 
  1. Done! Query the appropriate URL

Links

Help?!

  • Please reach out to me through github if you encounter any issues. Thanks for looking!