Deploy a Spring application connected to YugabyteDB Managed on Google Kubernetes Engine (GKE) by following the steps below.
This example uses the PetClinic application, connected to YugabyteDB Managed and containerized using Docker; refer to Connect a Spring Boot application.
Prerequisites
Before starting, you need to verify that the following are installed and configured:
-
Google Cloud Platform (GCP) account
-
GCP Cloud SDK
- For more information, refer to Cloud SDK.
-
Docker
-
Your containerized Spring Boot application
- For more information, refer to Connect a Spring Boot application
Deploy the application image to GKE
Create a repository in GCP
-
Go to https://console.cloud.google.com/ and sign in to GCP.
-
Type “artifact registry” in the search bar and select Artifact Registry.
-
Click Enable for the Artifact Registry API.
-
Click Create Repository.
-
Give your repository a name, make sure Docker is the selected format, and choose a region. Then click Create.
-
Got to your new repository and copy its URL.
Tag your application image in Docker
On your computer, do the following:
-
Configure Docker to use
gcloud
for authentication.$ gcloud auth configure-docker [region]-docker.pkg.dev
Replace [region] with the region you selected in GCP.
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
Replace [repo_url] with the URL of your repository.
-
Push your PetClinic image to your repo in GCP.
$ docker push [repo_url]/spring-petclinic:latest
Replace [repo_url] with the URL of your repository.
1dc94a70dbaa: Pushed 0d29ec96785e: Pushed 888ed16fa8d4: Pushed ...
Go to your repo in the GCP Artifact Registry to view the image you just pushed.
Deploy the image to GKE
In GCP, do the following:
-
Type “gke” in the search bar and select Kubernetes Engine.
-
Click Enable for the Kubernetes Engine API.
-
Click Create.
-
Click Configure under Autopilot.
-
Enter a Name, select a Region, and click Create.
-
After your cluster has been created, select Workloads in the left navigation panel.
-
Click Deploy.
-
Select Existing Container Image and click Select in the Image Path.
-
Click Artifact Registry, expand the folders, select the image under
spring-petclinic
, and click Select. -
Click Add Environment Variable.
-
Enter the following:
Key: JAVA_OPTS Value: -Dspring.profiles.active=yugabytedb \ -Dspring.datasource.url=jdbc:postgresql://[host]:[port]/petclinic?load-balance=true \ -Dspring.datasource.initialization-mode=never
Replace
[host]
and[port]
with the host and port number of your YugabyteDB Managed cluster. To obtain your cluster connection parameters, sign in to YugabyteDB Managed, select your cluster and navigate to Settings. -
Click Continue.
-
Enter a Name for your application and click Deploy (all other options should be auto-filled).
-
After your workload is deployed, click Expose on the Deployment Details.
-
Set Port to 80, Target Port to 8080, and Service Type to Load Balancer, then click Expose.
After the load balancer is created, the Service Details page displays.
-
Click the External Endpoints link (http://34.105.123.45/) to navigate to the PetClinic application.
The PetClinic sample application is now connected to your YugabyteDB Managed cluster and running on Kubernetes on GKE.