Kubernetes Engine
Create a Kubernetes cluster and deploy a container.
Kubernetes Engine 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

1
cd $HOME
2
git clone https://github.com/saturnism/jvm-helloworld-by-example
3
cd jvm-helloworld-by-example/helloworld-springboot-tomcat
Copied!

Build

1
./mvnw package
Copied!

Containerize

Enable API

Enable the Container Registry API so that you can push container images to Container Registry.
1
gcloud services enable containerregistry.googleapis.com
Copied!

Jib

Use Jib to containerize the application:
1
PROJECT_ID=$(gcloud config get-value project)
2
3
./mvnw compile com.google.cloud.tools:jib-maven-plugin:2.4.0:build \
4
-Dimage=gcr.io/${PROJECT_ID}/helloworld
Copied!
Learn different ways to containerize a Java application in the Container Image section.

Create Cluster

Enable API

1
gcloud services enable compute.googleapis.com
2
gcloud services enable container.googleapis.com
Copied!

Create Cluster

1
gcloud container clusters create helloworld-cluster \
2
--num-nodes 2 \
3
--enable-ip-alias \
4
--scopes=cloud-platform \
5
--network=default \
6
--machine-type n1-standard-1
Copied!
See Compute Engine Machine Types documentation for a list of Machine Types and the associated CPU/Memory resources.

Cluster Credentials

Kubernetes credentials are automatically retrieved and stored in your $HOME/.kube/config file. If you need to re-retrieve the credentials:
1
gcloud container clusters get-credentials helloworld-cluster
Copied!

Deploy

1
PROJECT_ID=$(gcloud config get-value project)
2
3
kubectl create deployment helloworld \
4
--image=gcr.io/${PROJECT_ID}/helloworld
Copied!
Check that the container is deployed:
1
kubectl get pods
Copied!

Expose

You can expose this one service using a single Network (L4) Load Balancer:
1
kubectl create service loadbalancer helloworld --tcp=8080:8080
Copied!
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 use a HTTP Load Balancer instead.

Connect

Find the Load Balancer's External IP address:
1
kubectl get services helloworld
Copied!
Initially, it may display that the External IP is <pending>.
1
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
2
helloworld LoadBalancer ... <pending> 8080:32414/TCP ...
Copied!
Re-check until the External IP is assigned.
Then connect with curl:
1
EXTERNAL_IP=$(kubectl get svc helloworld \
2
-ojsonpath='{.status.loadBalancer.ingress[0].ip}')
3
4
curl http://${EXTERNAL_IP}:8080
Copied!

Learn More