Cloud services are the MVP (Most Valuable Players) of modern IT. They give us:
- Easy scaling. If your users suddenly decide to hit your site all at once, you don't need to line up for hardware — the cloud will handle it for you.
- Time and cost savings. No need to maintain your own infrastructure, pay for electricity, or upgrade hardware.
- Flexibility. Clouds offer tons of services: from databases to machine learning. Want a database? Boom — it's ready.
- Resilience. Service outage in the cloud? Forget sleepless nights — the cloud will recover things for you.
But don't forget: cloud ≠ magic. If you deploy bad code, the cloud will just spread it faster. Deploying to the cloud should be done thoughtfully.
Overview of cloud platforms
You can use many platforms to deploy Spring Boot applications. Today we'll look at the three most popular:
| Platform | Description |
|---|---|
| AWS | Market leader in cloud tech. Has a huge set of services for containerization and deployment |
| GCP | Easy Kubernetes integration, developer-friendly |
| Azure | Microsoft's cloud platform. Great for enterprise solutions |
Each of these platforms has its own perks and quirks. So let's work with each one and try to deploy our app.
Preparing for deployment
Before you start you'll need to do a few steps:
- Create an account on the cloud platform.
- Signing up on AWS, GCP or Azure is your ticket to the cloud world. They usually offer free trial periods.
- Install the CLI for managing the cloud.
- AWS CLI, Google Cloud SDK (
gcloud) or Azure CLI — the tools we'll use to automate deployments.
- AWS CLI, Google Cloud SDK (
- Prepare the Docker image.
- In previous lectures we created a Docker image of our app. Let's remind how your
Dockerfilelooked:FROM openjdk:17-jdk-slim ARG JAR_FILE=target/my-spring-boot-app-1.0.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java", "-jar", "/app.jar"] - You can build the image with:
docker build -t my-spring-boot-app:1.0 .
- In previous lectures we created a Docker image of our app. Let's remind how your
Now let's "fly" through the clouds a bit.
Deploying to AWS
Creating an Elastic Container Registry (ECR)
AWS provides Elastic Container Registry to store Docker images.
- Login to AWS CLI:
Enter
aws configureAccess Key,Secret Keyand choose a region. - Create a repository:
aws ecr create-repository --repository-name my-spring-boot-app - Get Docker login:
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <your_repo_url> - Push the Docker image to ECR:
docker tag my-spring-boot-app:1.0 <your_repo_url>/my-spring-boot-app:1.0 docker push <your_repo_url>/my-spring-boot-app:1.0
Deploying to Elastic Beanstalk
AWS Elastic Beanstalk makes app deployment easier. Do the following:
- Install the Elastic Beanstalk CLI.
- Initialize the project:
Choose Docker as the platform.
eb init - Start the app:
eb create spring-boot-env
AWS will set up the infra, pull your container and run the app.
Deploying to Google Cloud Platform (GCP)
Uploading the Docker image to Google Container Registry (GCR)
- Log in to GCP:
gcloud auth login gcloud config set project <your_project_id> - Push the Docker image to GCR:
docker tag my-spring-boot-app gcr.io/<your_project_id>/my-spring-boot-app:1.0 docker push gcr.io/<your_project_id>/my-spring-boot-app:1.0
Deploying on Google Kubernetes Engine (GKE)
- Create a Kubernetes cluster:
gcloud container clusters create spring-boot-cluster \ --num-nodes=1 - Configure
kubectl:gcloud container clusters get-credentials spring-boot-cluster - Create a
deployment.yamlfile:apiVersion: apps/v1 kind: Deployment metadata: name: spring-boot-app spec: replicas: 1 selector: matchLabels: app: spring-boot-app template: metadata: labels: app: spring-boot-app spec: containers: - name: spring-boot-app image: gcr.io/<your_project_id>/my-spring-boot-app:1.0 ports: - containerPort: 8080 - Apply the configurations:
kubectl apply -f deployment.yaml - Make sure the app is running:
kubectl get pods
Deploying to Microsoft Azure
Uploading the image to Azure Container Registry (ACR)
- Create a resource in Azure for ACR:
az acr create --resource-group myResourceGroup --name myRegistry --sku Basic - Log in to ACR:
az acr login --name myRegistry - Push the Docker image:
docker tag my-spring-boot-app myregistry.azurecr.io/my-spring-boot-app:1.0 docker push myregistry.azurecr.io/my-spring-boot-app:1.0
Deploying to Azure App Service
- Create an App Service:
az webapp create --resource-group myResourceGroup --plan myAppServicePlan \ --name my-spring-boot-app --deployment-container-image-name myregistry.azurecr.io/my-spring-boot-app:1.0 - Set up automatic container updates:
az webapp config container set --name my-spring-boot-app \ --resource-group myResourceGroup --docker-custom-image-name myregistry.azurecr.io/my-spring-boot-app:1.0
Useful tips and common mistakes
- Don't forget about network settings. For example, on AWS or GCP you might forget to open security ports.
- Watch your image versioning. Don't use
latestunless absolutely necessary. - Monitor the logs. It's super convenient to do this in the cloud using built-in monitoring systems.
Now your app lives in the cloud! And not just lives — it's fully ready for real user load. P.S. If your service starts to hang, remember: sometimes clouds get into a "storm" too.
GO TO FULL VERSION