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.
cd $HOME
git clone https://github.com/saturnism/jvm-helloworld-by-example
cd jvm-helloworld-by-example/helloworld-springboot-tomcat
./mvnw package
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
gcloud services enable compute.googleapis.com
gcloud services enable container.googleapis.com
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
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) 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
Last modified 3yr ago