Deploying to Google Cloud Platform
You can deploy JHipster applications to Google Cloud Platform and run on:
- Virtual machines with Google Compute Engine
- Containers in Kubernetes with Google Kubernetes Engine
- Platform as a Service with Google App Engine
Before you start
Install and authenticate with the gcloud SDK on your local environment to access
gcloud CLI. For more information, visit this link:
Deploy to Google App Engine
Google App Engine is a fully managed Platform as a Service that can automatically scale up application instances under load, and scale down to zero when not used.
You can use the Google App Engine generator to generate and deploy JHipster application. Google App Engine generator supports monolith and micro-service applications, with Cloud SQL MySQL/PostgreSQL database.
Deploying Monoliths to Google App Engine
- Generate a new monolith application:
- Run Google App Engine generator:
- Optionally create a new Cloud SQL instance if creating a brand new application
This generator will:
src/main/appengine/app.yamlthat describes the App Engine instance and scaling configuration.
- Add the App Engine plugin to Maven / Gradle.
To deploy: Please note that currently the Google App Engine generator only supports deployments to App Engine Standard (Java 11) environment.
- Use the App Engine plugin to deploy:
./mvnw package appengine:deploy -DskipTests -Pgae,prod,prod-gaeor using Gradle
./gradlew appengineDeploy -Pgae -Pprod-gae
Deploying Microservices to Google App Engine
Google Cloud supports micro-service architecture on GAE
by isolating each micro-service as a separate service. We use a
to route the requests from the gateway to each micro-service. Therefore, in order to deploy microservices to GAE you will
need to deploy the gateway and each microservice as separate services.
Following are the steps that needs to be carried out.
Run the GAE sub-generator on each micro-service. It is important to run this as the first step as the gateway application setup will depend on this.
Run the GAE sub-generator on the gateway application. This will prompt for some additional questions in order to create the
Deploy each microservice and the gateway application using
./mvnw package appengine:deploy -DskipTests -Pgae,prod,prod-gaefor Maven or
./gradlew appengineDeploy -Pgae -Pprod-gaefor gradle.
Note 1: If you are using Windows, we recommend using Windows Subsystem for Linux or jhipster-devbox to avoid Windows spedific issues such as, https://github.com/jhipster/generator-jhipster/issues/11249
Note 2: If you are using Cloud SQL, you need to add Cloud SQL Client role to the App Engine service account. Refer, https://cloud.google.com/sql/docs/mysql/connect-app-engine#setting_up
In addition, Google App Engine provides a full suite of features to manage your application:
- Traffic Splitting - Deploy multiple versions of your application and split traffic to different versions. This is also great for canary new changes.
- Stackdriver Logging - Automatically capture and store application logs in centralized logging that can be searched, monitored, and exported.
- Error Reporting - Automatically extract errors and exceptions for the log and notify you of new errors.
- Cloud Debugger - Allow you to debug your production application without stopping the world. If you needed more log messages to diagnose the issue, add new log messages without redeploying/restarting your application.
You can watch a walk through of features in 2018 JHipster Conf video on the Google App Engine generator with Ray Tsang and Ludovic Champenois.
Deploy to Google Kubernetes Engine
Google Kubernetes Engine is a fully managed Kubernetes cluster as a service. Once provisioned, you can deploy your containers and JHipster applications using standard Kubernetes commands.
- Enable API:
gcloud services enable container.googleapis.com containerregistry.googleapis.com
kubectlCLI if not already installed:
gcloud components install kubectl
- Create a new Google Kubernetes Engine cluster:
gcloud container clusters create mycluster --zone us-central1-a --machine-type n1-standard-4
Once the cluster is created, you can use JHipster Kubernetes generator to generate the deployment descriptors.
- Generate Kubernetes deployment files:
- If you want to use Google Container Registry to publish container images in a private registry:
- What should we use for the base Docker repository name set to
Build the container image.
- If you use Google Container Registry, you can build directly to the registry without local Docker daemon:
./mvnw package -Pprod jib:build
- Otherwise, build to Docker daemon:
./mvnw package -Pprod jib:dockerBuild
Deploy to Kubernetes cluster:
- Apply the Kubernetes configurations:
For full Kubernetes generator features, see Deploying to Kubernetes.
To enable HTTPS for your cluster, see Ray Tsang’s External Load Balancing docs.
You can force the use of HTTPS by adding the following configuration to your
// Spring MVC http.requiresChannel(channel -> channel .requestMatchers(r -> r.getHeader("X-Forwarded-Proto") != null).requiresSecure()); // WebFlux http.redirectToHttps(redirect -> redirect .httpsRedirectWhen(e -> e.getRequest().getHeaders().containsKey("X-Forwarded-Proto")));