Deploy a Spring application connected to YugabyteDB Managed on Kubernetes locally using minikube 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:
-
kubectl
- For more information, refer to Install and Set Up kubectl.
- Kubernetes API
-
minikube
- For more information, refer to minikube start.
-
Docker
-
Your containerized Spring Boot application
- For more information, refer to Connect a Spring Boot application.
Start minikube
-
Start Docker (or another minkube-compatible container/VM manager) on your computer.
-
Start minikube.
$ minikube start
😄 minikube v1.22.0 on Darwin 11.5.1 (arm64) ✨ Automatically selected the docker driver 👍 Starting control plane node minikube in cluster minikube 🚜 Pulling base image ... 💾 Downloading Kubernetes v1.21.2 preload ... > gcr.io/k8s-minikube/kicbase...: 326.19 MiB / 326.19 MiB 100.00% 10.82 Mi > preloaded-images-k8s-v11-v1...: 522.45 MiB / 522.45 MiB 100.00% 15.90 Mi 🔥 Creating docker container (CPUs=2, Memory=4000MB) ... 🐳 Preparing Kubernetes v1.21.2 on Docker 20.10.7 ... ▪ Generating certificates and keys ... ▪ Booting up control plane ... ▪ Configuring RBAC rules ... 🔎 Verifying Kubernetes components... ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5 🌟 Enabled addons: storage-provisioner, default-storageclass 🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
-
Open a 2nd terminal and start the minikube dashboard.
$ minikube dashboard
🔌 Enabling dashboard ... ▪ Using image kubernetesui/dashboard:v2.1.0 ▪ Using image kubernetesui/metrics-scraper:v1.0.4 🤔 Verifying dashboard health ... 🚀 Launching proxy ... 🤔 Verifying proxy health ... 🎉 Opening http://127.0.0.1:51726/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
This opens the dashboard. Keep this tab open. You’ll use it later to check on your application deployment.
Deploy the application image to minikube
To deploy the application, you first point your shell to minikube’s Docker daemon. This ensures that Docker and kubectl
will use your minikube container registry instead of the Docker container registry. Then you create a manifest file and use this to create the service and deployment in minicube.
Point your shell to minikube
-
In your first terminal, run the following command:
$ minikube docker-env
export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://127.0.0.1:58018" export DOCKER_CERT_PATH="/Users/gavinjohnson/.minikube/certs" export MINIKUBE_ACTIVE_DOCKERD="minikube" # To point your shell to minikube's docker-daemon, run: # eval $(minikube -p minikube docker-env)
-
Run the following command to point your shell to minikube's docker-daemon:
$ eval $(minikube -p minikube docker-env)
-
Build your image again.
$ ./mvnw spring-boot:build-image
-
Tag your image again.
$ docker tag [image_id] spring-petclinic
You can find your image id by running
docker image ls
.
Create the manifest file and deploy in minikube
-
Create a new file named
manifest-minikube.yml
, enter the following contents, and save it:apiVersion: v1 kind: Service metadata: name: spring-petclinic labels: run: spring-petclinic spec: selector: app: spring-petclinic ports: - protocol: TCP port: 8080 targetPort: 8080 type: LoadBalancer --- apiVersion: apps/v1 kind: Deployment metadata: name: spring-petclinic labels: app: spring-petclinic spec: replicas: 2 selector: matchLabels: app: spring-petclinic template: metadata: labels: app: spring-petclinic spec: containers: - name: spring-petclinic image: spring-petclinic imagePullPolicy: Never ports: - containerPort: 8080 env: - name: 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 you cluster and navigate to Settings. -
Create the service and deployment in minikube using the manifest file.
$ kubectl create -f manifest-minikube.yml
service/spring-petclinic created deployment.apps/spring-petclinic created
-
Open a 3rd terminal and externally expose your load balancer.
$ minikube tunnel
🏃 Starting tunnel for service spring-petclinic.
-
Wait for your application to come online (typically several minutes).
-
Go to the local IP and Port you configured in your manifest file (http://127.0.0.1:8080).
The PetClinic sample application is now connected to your YugabyteDB Managed cluster and running on Kubernetes locally on minikube.
Tip
To reset your minikube setup, you can run the following commands:
$ kubectl delete -f manifest-minikube.yml
$ minikube stop
$ minikube delete --all