In this tutorial, you use an Oracle Cloud Infrastructure account to set up a Kubernetes
cluster. Then, you deploy a Spring Boot application to your cluster.
If you want to use an OCI Free Tier Linux compute instance to manage your deployment,
the following sections provide information to get the required software installed.
Install a Linux VM with an Always Free compute shape, on Oracle Cloud
Infrastructure. You will need a machine with ssh support to connect
to your Linux instance.
Repeat for Scope:<second-availability-domain> and
<third-availability-domain>. Each region must have
at least 50 GB of block volume available.
Find out how many Flexible Load Balancers you have available:
Filter for the following options:
Service: LbaaS
Scope:<your-region>. Example:
us-ashburn-1
Resource:<blank>
Compartment:<tenancy-name> (root)
Find the number of available flexible load balancers:
Limit Name:lb-flexible-count
Available: minimum 1
Note
This tutorial creates three compute instances with a VM.Standard.E3.Flex shape
for the cluster nodes. To use another shape, filter for its core count. For
example, for VM.Standard2.4, filter for Cores for Standard2 based VM and BM
Instances and get the count.
This tutorial uses a 'Quick Create' workflow to create a cluster with a public
regional subnet that hosts a flexible load balancer. To use a different load
balancer, you can use a custom workflow to explicitly specify which existing network
resources to use, including the existing subnets in which to create the load
balancers.
To use another bandwidth for the load balancer, filter for its count, for
example 100-Mbps bandwidth or 400-Mbps bandwidth.
The Python virtualenv creates a folder that contains all the
executables and libraries for your project.
The virtualenvwrapper is an extension to virtualenv.
It provides a set of commands, which makes working with virtual environments much
more pleasant. It also places all your virtual environments in one place. The
virtualenvwrapper provides tab-completion on environment
names.
Install
virtualenv.
Copy
pip3 install --user virtualenv
Install
virtualenvwrapper.
Copy
pip3 install --user virtualenvwrapper
Find the location of the virtualenvwrapper.sh
script.
Copy
grep -R virtualenvwrapper.sh
Example
paths:
Linux example:
/home/ubuntu/.local/bin/virtualenvwrapper.sh
A Docker image holds an application, its dependencies, and instructions to run the
application.
Note
For MacOS, you can remove the sudo in the
docker commands.
Change into the gs-spring-boot-docker/initial directory.
Create a file named Dockerfile.
Copy
FROM openjdk:8-jdk
RUN addgroup --system spring && adduser --system spring -ingroup spring
USER spring:spring
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Build the Docker image:
Copy
sudo docker build -t spring-boot-hello .
Example output:
Successfully built xxxxxxxxxxxx
Successfully tagged spring-boot-hello:latest
Run the Docker image:
Copy
sudo docker run -p 8080:8080 -t spring-boot-hello
You get the same result as running the local app.
Stop the running application.
Congratulations! You have successfully created a Spring Boot Docker
image.
<repo-prefix>/<image-name> from the
Create a Docker Repository section.
Example:
sudo docker tag spring-boot-hello iad.ocir.io/my-namespace/spring-projects/spring-boot-hello
In this example, the components are:
<repo-url>:iad.ocir.io/my-namespace/
<repo-name>:spring-projects/spring-boot-hello
Note
OCI Container Registry now supports creating a registry repo in any
compartment rather than only in the root compartment (tenancy). To push the
image to the repo you created, combine the registry URL with the exact repo
name. OCI Container Registry matches the unique repo name and pushes your
image.
Check your Docker images to see if the image is tagged.
Copy
sudo docker images
The tagged image points to your local image and has the same
image ID as your local image.
After you deploy your app, it might take the load balancer a few seconds to
load.
Check if the load balancer is live:
Copy
kubectl get service
Repeat the command until load balancer is assigned a public IP address.
Use the load balancer IP address to connect to your app in a browser:
Copy
http://<load-balancer-IP-address>:8080
The browser displays: Spring Boot Hello World!
(Optional)
To undeploy your application from the cluster, run the following command:
Copy
kubectl delete -f sb-app.yaml
Output:
deployment.apps "sbapp" deleted
service "sbapp-lb" deleted
Your application is now removed from your cluster.
What's Next 🔗
Congratulations! You have successfully created a Hello World application, deployed it to a
Kubernetes cluster, and made it accessible on the internet, using the Spring Boot
framework.
To explore more information about development with Oracle products, check out these
sites: