​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.
cd $HOMEgit clone https://github.com/saturnism/jvm-helloworld-by-examplecd jvm-helloworld-by-example/helloworld-springboot-tomcat
./mvnw package
Enable the Container Registry API so that you can push container images to Container Registry.
gcloud services enable containerregistry.googleapis.com
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
Learn different ways to containerize a Java application in the Container Image section.
gcloud services enable compute.googleapis.comgcloud services enable container.googleapis.com
Create a VPC-native Kubernetes Engine cluster.
gcloud container clusters create helloworld-cluster \--num-nodes 2 \--enable-ip-alias \--scopes=cloud-platform \--network=default \--machine-type n1-standard-1
See Compute Engine Machine Types documentation for a list of Machine Types and the associated CPU/Memory resources.
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
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
You can expose this one service using a single Network (L4) Load Balancer:
kubectl create service loadbalancer helloworld --tcp=8080:8080
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.
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) AGEhelloworld 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