This is a simple code example of performing a Blue/Green and a Canary deployment of a Docker-packaged Spring Boot Microservice to Google Kubernetes Engine.
It’s just the basics to get you started in 10 minutes.
Checking out the source
You can check out the source here.
It’s a basic Microservice that echoes a message that you pass.
git clone https://github.com/johndobie-blog/spring-boot-gkeAll of the instructions are also here
https://github.com/johndobie-blog/spring-boot-gke
Run Standalone
Start the Microservice locally and pass it a test message to echo.
mvn clean spring-boot:run
curl http://localhost:8080/echo?message=testmessage
Host[192.168.0.13] : testmessageRun In Docker Locally
Create the image and then run the service in docker.
docker image build --tag="spring-boot/echo" .
docker run -p 8080:8080 -t "spring-boot/echo" Run In Google Shell
https://console.cloud.google.com/cloudshell/open
?git_repo=https://github.com/johndobie-blog/spring-boot-ke.git
&page=editor
&open_in_editor=README.md
mvn clean spring-boot:runRun In Google Shell with Docker
https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/johndobie-blog/spring-boot-gke.git&page=editor&open_in_editor=README.md
mvn clean install
docker image build --tag="spring-boot/echo" .
docker run -p 8080:8080 -t "spring-boot/echo" Run With Kubernetes
Open Google Shell
https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/johndobie-blog/spring-boot-gke.git&page=editor&open_in_editor=README.mdCreate and set the project
gcloud projects create spring-boot-kubernetes-echo --name="Spring Boot Echo on GKE"
gcloud config set project spring-boot-kubernetes-echo
export PROJECT_ID=”$(gcloud config get-value project -q)”
gcloud projects list
gcloud beta billing projects link spring-boot-kubernetes-echo --billing-account 003146-4D6988-3DC95CCreate the Docker Image
gcloud services enable containerregistry.googleapis.com
docker build -t echo-container-image .
docker tag echo-container-image gcr.io/spring-boot-kubernetes-echo/echo:v1
docker push gcr.io/spring-boot-kubernetes-echo/echo:v1Create the Kubernetes cluster
gcloud services enable compute.googleapis.com container.googleapis.com
gcloud container clusters create echo-kubernetes-cluster \
--num-nodes 4 \
--machine-type n1-standard-1 \
--zone us-central1-cDeploy The Application
cd src/main/docker
kubectl apply -f deploy-echo-v1.yaml
or
kubectl create deployment echo-deployment --image=gcr.io/spring-boot-kubernetes-echo/echo:v1
kubectl get deployments
kubectl get podsCreate a load balancer and expose the service
kubectl expose deployment echo-deployment
--type=LoadBalancer --port 80 --target-port 8080
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
echo-deployment LoadBalancer 10.59.247.132 35.222.75.46 80:31383/TCP 80sUse the external address to access the service
http://35.222.75.46/echo?message=test
Scale the pods up or down
kubectl scale deployment echo-deployment --replicas=3
kubectl get pods
kubectl scale deployment echo-deployment --replicas=1
kubectl get podsTear The Project Down
gcloud projects delete spring-boot-kubernetes-echo -q
All of the instructions are in the readme above.








Leave a Reply
You must be logged in to post a comment.