update to latest release
Example Petclinic deployment on Google Cloud Platform into Google Kubernetes Engine with Istio. This is based on Spring PetClinic Microservices
This example has:
Create a new Project if you haven’t done so already.
$ export PROJECT_ID=... $ gcloud project create $PROJECT_ID
Set the default Project ID:
$ gcloud config set core/project $PROJECT_ID
Use gcloud to provision a multi-zone Kubernetes Engine cluster.
gcloud
$ gcloud services enable compute.googleapis.com container.googleapis.com $ CLOUDSDK_CONTAINER_USE_V1_API_CLIENT=false $ gcloud container clusters create petclinic-cluster \ --cluster-version=1.9.6 \ --region=us-central1 \ --num-nodes=2 \ --machine-type=n1-standard-2 \ --enable-autorepair \ --no-enable-cloud-logging \ --no-enable-cloud-monitoring
Install the basics:
$ ISTIO_VERSION=0.7.1 $ curl -L https://git.io/getLatestIstio | sh - $ cd istio-$ISTIO_VERSION $ kubectl apply -f install/kubernetes/istio.yaml --as=admin --as-group=system:masters
Update Sidecar Injector to limit Istio to 10.0.0.0/8 network:
install/kubernetes/istio-sidecar-injector-configmap-release.yaml
initContainers
args
... initContainers: - name: istio-init image: docker.io/istio/proxy_init:0.7.1 args: - "-p" - {{ .MeshConfig.ProxyListenPort }} - "-u" - 1337 # ADD THE FOLLOWING LINES - -i - 10.0.0.0/8 # ADD THE ABOVE LINES ...
Install Sidecar Injector:
$ install/kubernetes/webhook-create-signed-cert.sh \ --service istio-sidecar-injector \ --namespace istio-system \ --secret sidecar-injector-certs $ kubectl apply -f install/kubernetes/istio-sidecar-injector-configmap-release.yaml $ cat install/kubernetes/istio-sidecar-injector.yaml | \ ./install/kubernetes/webhook-patch-ca-bundle.sh > \ install/kubernetes/istio-sidecar-injector-with-ca-bundle.yaml $ kubectl apply -f install/kubernetes/istio-sidecar-injector-with-ca-bundle.yaml
Enable Sidecar Injector on default namespace:
default
$ kubectl label namespace default istio-injection=enabled
$ gcloud spanner instances create petclinic --config=regional-us-central1 --nodes=1 --description="PetClinic Spanner Instance" $ gcloud spanner databases create petclinic --instance=petclinic $ gcloud spanner databases ddl update petclinic --instance=petclinic --ddl="$(<petclinic/db/spanner.ddl)"
$ gcloud services enable cloudprofiler.googleapis.com clouddebugger.googleapis.com
Create a new Service Account for the microservices:
$ gcloud iam service-accounts create petclinic --display-name "PetClinic Service Account"
Grant IAM Roles to the Service Account:
$ gcloud projects add-iam-policy-binding $PROJECT_ID \ --member serviceAccount:petclinic@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/cloudprofiler.agent $ gcloud projects add-iam-policy-binding $PROJECT_ID \ --member serviceAccount:petclinic@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/clouddebugger.agent $ gcloud projects add-iam-policy-binding $PROJECT_ID \ --member serviceAccount:petclinic@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/cloudtrace.agent $ gcloud projects add-iam-policy-binding $PROJECT_ID \ --member serviceAccount:petclinic@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/spanner.databaseUser
Create a new JSON Service Account Key. Keep it secure!
$ gcloud iam service-accounts keys create ~/petclinic-service-account.json \ --iam-account petclinic@$PROJECT_ID.iam.gserviceaccount.com
$ mvn install
Build all images:
$ mvn package install -PbuildDocker
Build just one image:
$ mvn package install -PbuildDocker -pl spring-petclinic-customers-service
Update docker-compose.yml file so that secrets.petclinic-credentials.file points to the JSON file.
docker-compose.yml
secrets.petclinic-credentials.file
Run everything:
$ echo "PROJECT_ID=$PROJECT_ID" > .env $ docker-compose up
Store Service Account as a Kubenetes Secret:
$ kubectl create secret generic petclinic-credentials --from-file=$HOME/petclinic-service-account.json
Deploy Application:
$ kubectl apply -f kubernetes/
Deploy Route Rules:
$ kubectl apply -f istio/
Install the Travis CLI:
$ brew install travis
Or, follow the Travis CLI Installation instruction
Login to Travis
$ travis login
Or, optionally login with travis login --github-token=... to avoid typing password, etc.
travis login --github-token=...
Configure Docker credentials:
$ travis env set DOCKER_USERNAME your_username $ travis env set DOCKER_PASSWORD your_password
Create a CI/CD Service Account, assign roles, and create a JSON file:
$ gcloud iam service-accounts create travis-ci --display-name "Travis CI/CD" $ gcloud projects add-iam-policy-binding $PROJECT_ID \ --member serviceAccount:travis-ci@$PROJECT_ID.iam.gserviceaccount.com \ --role roles/container.developer $ gcloud iam service-accounts keys create ~/travis-ci-petclinic.json \ --iam-account travis-ci@$PROJECT_ID.iam.gserviceaccount.com
Encrypt and Store the Travis CI/CD Service Account:
$ travis encrypt-file ~/travis-ci-petclinic.json
Travis asks you to add a line to before_install section. Make sure it’s updated.
before_install
Set the Google Cloud Platform Project ID for reference in the build:
$ travis env set PROJECT_ID $PROJECT_ID
Commit .travis.yml
.travis.yml
Use the following command from the CLI or in your CI/CD pipeline:
jx step split monorepo -o petclinic-gcp --glob "spring-*"
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802032778号
Google Cloud Native Spring Boot PetClinic
Example Petclinic deployment on Google Cloud Platform into Google Kubernetes Engine with Istio. This is based on Spring PetClinic Microservices
This example has:
Google Cloud Platform Project
Create a new Project if you haven’t done so already.
Set the default Project ID:
Kubernetes Engine Cluster
Use
gcloudto provision a multi-zone Kubernetes Engine cluster.Istio
Install the basics:
Update Sidecar Injector to limit Istio to 10.0.0.0/8 network:
install/kubernetes/istio-sidecar-injector-configmap-release.yamlinitContainersargsblock:Install Sidecar Injector:
Enable Sidecar Injector on
defaultnamespace:Spanner
Debugging and Profiling
Generate Service Account
Create a new Service Account for the microservices:
Grant IAM Roles to the Service Account:
Create a new JSON Service Account Key. Keep it secure!
Build
Compile and Install to Maven
Build Docker Images
Build all images:
Build just one image:
Run
Docker Compose
Update
docker-compose.ymlfile so thatsecrets.petclinic-credentials.filepoints to the JSON file.Run everything:
Kubernetes
Store Service Account as a Kubenetes Secret:
Deploy Application:
Deploy Route Rules:
Travis CI/CD
Install the Travis CLI:
Or, follow the Travis CLI Installation instruction
Login to Travis
Or, optionally login with
travis login --github-token=...to avoid typing password, etc.Configure Docker credentials:
Create a CI/CD Service Account, assign roles, and create a JSON file:
Encrypt and Store the Travis CI/CD Service Account:
Travis asks you to add a line to
before_installsection. Make sure it’s updated.Set the Google Cloud Platform Project ID for reference in the build:
Commit
.travis.ymlGenerating/updating the separate microservices
Use the following command from the CLI or in your CI/CD pipeline: