Connecting a Spring Boot Application to Yugabyte Cloud and Deploying It on Google Kubernetes Engine (GKE)
- Published on
- • 5 mins read
- Written by
- Name
- Gavin Johnson
- @thtmnisamnstr

This post was originally published on Yugabyte’s blog.
Spring Boot is one of the most popular frameworks for building cloud native applications. It makes configuring an application easy and offers tons of starters to get you off the ground quickly. Each Spring Boot application is stand-alone and self-contained, which makes them easy to deploy in a distributed fashion – to containers or, even better, on Kubernetes.
Yugabyte Cloud is a perfect match for Spring Boot applications, especially ones made highly available with Kubernetes. Yugabyte Cloud gives you a PostgreSQL-compatible database that is resilient and scalable, just like the applications you run on k8s. You can scale your YugabyteDB cluster out (or in) with just a few clicks. So you can spend less time worrying about running your database and more time focused on building better software. It’s cloud native SQL for cloud native applications. Sign up for Yugabyte Cloud today.
Walkthrough
In this post, we’ll walk you through connecting a Spring Boot application to Yugabyte Cloud and deploying it on Kubernetes via Google Kubernetes Engine (GKE). You can view our walkthrough on connecting a Spring Boot application to Yugabyte Cloud and deploying it on Kubernetes via Amazon Elastic Kubernetes Service (EKS) here and via minikube here. We’ll be using a slightly updated version of the popular Spring Boot PetClinic sample application that has a profile making it compatible with YugabyteDB. The repository for this is at https://github.com/yugabyte/spring-petclinic.
In this walkthrough, you will:
- Create a free Yugabyte Cloud account and database cluster
- Download the Spring Boot PetClinic sample application and connect it to Yugabyte Cloud
- Containerize the Spring Boot PetClinic sample application
- Deploy the Spring Boot PetClinic sample application image to GKE
Prerequisites
- Java 8 or newer (full JDK)
- Git
- Docker
- GCP Cloud SDK
Note: Anything in brackets [ ] needs to be replaced with information from your deployment.
Create a free Yugabyte Cloud account and database cluster
Go to https://cloud.yugabyte.com/signup and sign up for a Yugabyte Cloud account. After you’ve signed up and verified your email address, go to https://cloud.yugabyte.com/login and sign in.
Copy the default admin credentials by clicking the Copy Credentials link. Then check the “I have copied the admin credentials” checkbox and click the Create Cluster button.
In the Name text box, enter “all-ips”. In the IP Address(es) or Range text box, enter “0.0.0.0/0”. Click the Save button. This will allow traffic from all IP addresses to your cluster.
Your cluster is now created in Yugabyte Cloud and is accessible to all IP addresses. Leave this page open, as you’ll be accessing the Cloud Shell later to create an application database and user.
Download the Spring Boot PetClinic sample application and connect it to Yugabyte Cloud
Note: Instructions for how to connect this application to YugabyteDB are in spring-petclinic/src/main/resources/db/yugabytedb/petclinic_db_setup_yugabytedb.md
from the repo you clone below.
On your computer from terminal, clone the Spring Boot PetClinic sample application:
git clone https://github.com/yugabyte/spring-petclinic.git
.$ git clone https://github.com/yugabyte/spring-petclinic.git Cloning into 'spring-petclinic'... remote: Enumerating objects: 8616, done. remote: Counting objects: 100% (18/18), done. remote: Compressing objects: 100% (18/18), done. remote: Total 8616 (delta 1), reused 13 (delta 0), pack-reused 8598 Receiving objects: 100% (8616/8616), 7.29 MiB | 19.03 MiB/s, done. Resolving deltas: 100% (3268/3268), done.
cd spring-petclinic
.Copy the contents of
spring-petclinic/src/main/resources/db/yugabytedb/user.sql
.Click the Launch Cloud Shell button.
Enter the admin password you copied previously. After you enter the password, you will have a standard YSQL shell (exactly like a PSQL shell in PostgreSQL) that you can interact with from your browser.
Password for user admin: ysqlsh (11.2-YB-2.4.2.0-b0) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. yugabyte=#
The PetClinic sample application is now connected to your Yugabyte Cloud cluster and running locally.
Containerize the Spring Boot PetClinic sample application
Start Docker on your computer and containerize your Spring Boot PetClinic sample application:
./mvnw spring-boot:build-image
.Tag your image:
docker tag [image_id] spring-petclinic
– you can find your image id by runningdocker image ls
.Run your image as a container in Docker to make sure it’s working correctly:
docker run -d --name=spring-petclinic -p 8080:8080 -e JAVA_OPTS="-Dspring.profiles.active=yugabytedb -Dspring.datasource.url=jdbc:postgresql://[host]:[port]/petclinic?load-balance=true -Dspring.datasource.initialization-mode=never" spring-petclinic
.a. Go to http://localhost:8080. The PetClinic sample application should be available.
The PetClinic sample application is now connected to your Yugabyte Cloud cluster and running locally on Docker.
Deploy the Spring Boot PetClinic sample application image to Google Kubernetes Engine (GKE)
Go to https://console.cloud.google.com/ and sign up for/sign in to Google Cloud Platform (GCP).
On your computer from terminal, configure Docker to use gcloud for authentication:
gcloud auth configure-docker [region]-docker.pkg.dev
.$ gcloud auth configure-docker us-west1-docker.pkg.dev Adding credentials for: us-west1-docker.pkg.dev After update, the following will be written to your Docker config file located at [/Users/gavinjohnson/.docker/config.json]: { "credHelpers": { "us-west1-docker.pkg.dev": "gcloud" } } Do you want to continue (Y/n)? y Docker configuration file updated.
Tag your PetClinic image with your Artifact Registry repo:
docker tag spring-petclinic:latest [repo_url]/spring-petclinic:latest
.Push your PetClinic image to your repo in Artifact Registry:
docker push [repo_url]/spring-petclinic:latest
.$ docker push us-west1-docker.pkg.dev/gavins-sandbox-320519/spring-petclinic/spring-petclinic:latest The push refers to repository [us-west1-docker.pkg.dev/gavins-sandbox-320519/spring-petclinic/spring-petclinic] 1dc94a70dbaa: Pushed 0d29ec96785e: Pushed 888ed16fa8d4: Pushed ...
Click the Continue button.
The PetClinic sample application is now connected to your Yugabyte Cloud cluster and running on Kubernetes on GKE.
What’s Next?
Give Yugabyte Cloud a try by signing up for a free tier account in a couple of minutes. Got questions? Feel free to ask them in our YugabyteDB community Slack channel.