Spring Boot on GCP
  • Introduction
  • Getting Started
    • Google Cloud Platform
    • Cloud Shell
    • gcloud CLI
    • Hello World!
      • Cloud Shell
      • App Engine
      • Cloud Run
      • Kubernetes Engine
      • Compute Engine
      • Cloud Functions
  • Application Development
    • Development Tools
    • Spring Cloud GCP
    • Cloud Services
      • Databases
        • Cloud SQL
        • Cloud Spanner
        • Cloud Firestore
          • Datastore Mode
          • Native Mode
      • Messaging
        • Cloud Pub/Sub
        • Kafka
      • Secret Management
      • Storage
      • Cache
        • Memorystore Redis
        • Memorystore Memcached (beta)
      • Other Services
    • Observability
      • Trace
      • Logging
      • Metrics
      • Profiling
      • Debugging
    • DevOps
      • Artifact Repository
  • Deployment
    • Runtime Environments
    • Container
      • Container Image
      • Secure Container Image
      • Container Awareness
      • Vulnerability Scanning
      • Attestation
    • Kubernetes
      • Kubernetes Cluster
      • Deployment
      • Resources
      • Service
      • Health Checks
      • Load Balancing
        • External Load Balancing
        • Internal Load Balancing
      • Scheduling
      • Workload Identity
      • Binary Authorization
    • Istio
      • Getting Started
      • Sidecar Proxy
  • Additional Resources
    • Code Labs
    • Presentations / Videos
    • Cheat Sheets
Powered by GitBook
On this page
  • Getting Started
  • Clone
  • Build
  • Containerize
  • Create Cluster
  • Deploy
  • Expose
  • Connect
  • Learn More

Was this helpful?

  1. Getting Started
  2. Hello World!

Kubernetes Engine

Create a Kubernetes cluster and deploy a container.

PreviousCloud RunNextCompute Engine

Last updated 4 years ago

Was this helpful?

is a secured and managed Kubernetes service so you can deploy containerized application in an enterprise/production-grade Kubernetes cluster with a click of a button.

Getting Started

Clone

cd $HOME
git clone https://github.com/saturnism/jvm-helloworld-by-example
cd jvm-helloworld-by-example/helloworld-springboot-tomcat

Build

./mvnw package

Containerize

Enable API

Enable the Container Registry API so that you can push container images to .

gcloud services enable containerregistry.googleapis.com

Jib

Use Jib to containerize the application:

PROJECT_ID=$(gcloud config get-value project)

./mvnw compile com.google.cloud.tools:jib-maven-plugin:2.4.0:build \
  -Dimage=gcr.io/${PROJECT_ID}/helloworld

Create Cluster

Enable API

gcloud services enable compute.googleapis.com
gcloud services enable container.googleapis.com

Create Cluster

gcloud container clusters create helloworld-cluster \
  --num-nodes 2 \
  --enable-ip-alias \
  --scopes=cloud-platform \
  --network=default \
  --machine-type n1-standard-1

Cluster Credentials

Kubernetes credentials are automatically retrieved and stored in your $HOME/.kube/config file. If you need to re-retrieve the credentials:

gcloud container clusters get-credentials helloworld-cluster

Deploy

PROJECT_ID=$(gcloud config get-value project)

kubectl create deployment helloworld \
  --image=gcr.io/${PROJECT_ID}/helloworld

Check that the container is deployed:

kubectl get pods

Expose

kubectl create service loadbalancer helloworld --tcp=8080:8080

Connect

Find the Load Balancer's External IP address:

kubectl get services helloworld

Initially, it may display that the External IP is <pending>.

NAME         TYPE           CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
helloworld   LoadBalancer   ...          <pending>     8080:32414/TCP   ...

Re-check until the External IP is assigned.

Then connect with curl:

EXTERNAL_IP=$(kubectl get svc helloworld \
  -ojsonpath='{.status.loadBalancer.ingress[0].ip}')

curl http://${EXTERNAL_IP}:8080

Learn More

Learn different ways to containerize a Java application in the section.

Create a .

See for a list of Machine Types and the associated CPU/Memory resources.

You can expose this one service using a single :

A Network (L4) Load Balancer is the easiest way to expose a single service for a demo. For production environment, you likely will need to instead.

Kubernetes Engine
Container Registry
Container Image
VPC-native Kubernetes Engine cluster
Compute Engine Machine Types documentation
Network (L4) Load Balancer
use a HTTP Load Balancer
Kubernetes from Basic to Advanced code lab
Spring Boot on GCP code lab
Spring to Kubernetes Faster and Easier