Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Commit 4eace1b

Browse files
committed
added files for pyroscope
1 parent 13b7306 commit 4eace1b

File tree

181 files changed

+6078
-11566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+6078
-11566
lines changed

CODEOWNERS

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Repo owners - Anthos DPE
2+
* @anthos-dpe
3+

README.md

+93-244
Large diffs are not rendered by default.

cloudbuild.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
# This configuration file is used to build and deploy the app into a
216
# GKE cluster using Google Cloud Build.
317
#

docs/development-guide.md

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Development Guide
2+
3+
This doc explains how to build and run the OnlineBoutique source code locally using the `skaffold` command-line tool.
4+
5+
## Prerequisites
6+
7+
- [Docker for Desktop](https://www.docker.com/products/docker-desktop).
8+
- kubectl (can be installed via `gcloud components install kubectl`)
9+
- [skaffold]( https://skaffold.dev/docs/install/), a tool that builds and deploys Docker images in bulk.
10+
- A Google Cloud Project with Google Container Registry enabled.
11+
- Enable GCP APIs for Cloud Monitoring, Tracing, Debugger, Profiler:
12+
```
13+
gcloud services enable monitoring.googleapis.com \
14+
cloudtrace.googleapis.com \
15+
clouddebugger.googleapis.com \
16+
cloudprofiler.googleapis.com
17+
```
18+
- [Minikube](https://minikube.sigs.k8s.io/docs/start/) (optional - see Local Cluster)
19+
- [Kind](https://kind.sigs.k8s.io/) (optional - see Local Cluster)
20+
21+
## Option 1: Google Kubernetes Engine (GKE)
22+
23+
> 💡 Recommended if you're using Google Cloud Platform and want to try it on
24+
> a realistic cluster. **Note**: If your cluster has Workload Identity enabled,
25+
> [see these instructions](/docs/workload-identity.md)
26+
27+
1. Create a Google Kubernetes Engine cluster and make sure `kubectl` is pointing
28+
to the cluster.
29+
30+
```sh
31+
gcloud services enable container.googleapis.com
32+
```
33+
34+
```sh
35+
gcloud container clusters create demo --enable-autoupgrade \
36+
--enable-autoscaling --min-nodes=3 --max-nodes=10 --num-nodes=5 --zone=us-central1-a
37+
```
38+
39+
```
40+
kubectl get nodes
41+
```
42+
43+
2. Enable Google Container Registry (GCR) on your GCP project and configure the
44+
`docker` CLI to authenticate to GCR:
45+
46+
```sh
47+
gcloud services enable containerregistry.googleapis.com
48+
```
49+
50+
```sh
51+
gcloud auth configure-docker -q
52+
```
53+
54+
3. In the root of this repository, run `skaffold run --default-repo=gcr.io/[PROJECT_ID]`,
55+
where [PROJECT_ID] is your GCP project ID.
56+
57+
This command:
58+
59+
- builds the container images
60+
- pushes them to GCR
61+
- applies the `./kubernetes-manifests` deploying the application to
62+
Kubernetes.
63+
64+
**Troubleshooting:** If you get "No space left on device" error on Google
65+
Cloud Shell, you can build the images on Google Cloud Build: [Enable the
66+
Cloud Build
67+
API](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com),
68+
then run `skaffold run -p gcb --default-repo=gcr.io/[PROJECT_ID]` instead.
69+
70+
4. Find the IP address of your application, then visit the application on your
71+
browser to confirm installation.
72+
73+
kubectl get service frontend-external
74+
75+
76+
## Option 2 - Local Cluster
77+
78+
1. Launch a local Kubernetes cluster with one of the following tools:
79+
80+
- To launch **Minikube** (tested with Ubuntu Linux). Please, ensure that the
81+
local Kubernetes cluster has at least:
82+
- 4 CPUs
83+
- 4.0 GiB memory
84+
- 32 GB disk space
85+
86+
```shell
87+
minikube start --cpus=4 --memory 4096 --disk-size 32g
88+
```
89+
90+
- To launch **Docker for Desktop** (tested with Mac/Windows). Go to Preferences:
91+
- choose “Enable Kubernetes”,
92+
- set CPUs to at least 3, and Memory to at least 6.0 GiB
93+
- on the "Disk" tab, set at least 32 GB disk space
94+
95+
- To launch a **Kind** cluster:
96+
97+
```shell
98+
kind create cluster
99+
```
100+
101+
2. Run `kubectl get nodes` to verify you're connected to the respective control plane.
102+
103+
3. Run `skaffold run` (first time will be slow, it can take ~20 minutes).
104+
This will build and deploy the application. If you need to rebuild the images
105+
automatically as you refactor the code, run `skaffold dev` command.
106+
107+
4. Run `kubectl get pods` to verify the Pods are ready and running.
108+
109+
5. Access the web frontend through your browser
110+
- **Minikube** requires you to run a command to access the frontend service:
111+
112+
```shell
113+
minikube service frontend-external
114+
```
115+
116+
- **Docker For Desktop** should automatically provide the frontend at http://localhost:80
117+
118+
- **Kind** does not provision an IP address for the service.
119+
You must run a port-forwarding process to access the frontend at http://localhost:8080:
120+
121+
```shell
122+
kubectl port-forward deployment/frontend 8080:8080
123+
```
124+
125+
## Cleanup
126+
127+
If you've deployed the application with `skaffold run` command, you can run
128+
`skaffold delete` to clean up the deployed resources.

docs/development-principles.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Development Principles
22

33
> **Note:** This document outlines guidances behind some development decisions
4-
> behind the Hipster Shop demo application.
4+
> behind the Online Boutique demo application.
55
66
### Minimal configuration
77

docs/img/architecture-diagram.png

-18 KB
Loading

docs/img/hipster-shop-frontend-1.png

-776 KB
Binary file not shown.

docs/img/hipster-shop-frontend-2.png

-358 KB
Binary file not shown.

docs/img/memorystore.png

167 KB
Loading
3.38 MB
Loading
570 KB
Loading

docs/memorystore.md

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Memorystore (redis) + OnlineBoutique
2+
3+
This guide contains instructions for overriding the default in-cluster `redis` database for `cartservice` with Memorystore (redis).
4+
5+
Important notes:
6+
- You can connect to a Memorystore (redis) instance from GKE clusters that are in the same region and use the same network as your instance.
7+
- You cannot connect to a Memorystore (redis) instance from a GKE cluster without VPC-native/IP aliasing enabled.
8+
9+
![Architecture diagram with Memorystore](./img/memorystore.png)
10+
11+
## Steps
12+
13+
1. Create a GKE cluster with VPC-native/IP aliasing enabled.
14+
15+
```sh
16+
PROJECT_ID="<your-project-id>"
17+
ZONE="<your-GCP-zone>"
18+
REGION="<your-GCP-region>"
19+
20+
gcloud container clusters create onlineboutique \
21+
--project=${PROJECT_ID} \
22+
--zone=${ZONE} \
23+
--machine-type=e2-standard-2 \
24+
--enable-ip-alias
25+
```
26+
27+
2. Enable the Memorystore (redis) service on your project.
28+
29+
```sh
30+
gcloud services enable redis.googleapis.com --project=${PROJECT_ID}
31+
```
32+
33+
3. Create the Memorystore (redis) instance.
34+
35+
```sh
36+
gcloud redis instances create redis-cart --size=1 --region=${REGION} --zone=${ZONE} --redis-version=redis_5_0 --project=${PROJECT_ID}
37+
```
38+
39+
After a few minutes, you will see the `STATUS` as `READY` when your Memorystore instance will be successfully provisioned:
40+
41+
```sh
42+
gcloud redis instances list --region ${REGION}
43+
```
44+
45+
4. Update current manifests to target this Memorystore (redis) instance.
46+
47+
```sh
48+
cp ./release/kubernetes-manifests.yaml ./release/updated-manifests.yaml
49+
REDIS_IP=$(gcloud redis instances describe redis-cart --region=${REGION} --format='get(host)')
50+
sed -i "s/value: \"redis-cart:6379\"/value: \"${REDIS_IP}\"/g" ./release/updated-manifests.yaml
51+
```
52+
53+
In addition, in the `./release/updated-manifests.yaml` file you need also to manually remove the `Deployment` and `Service` sections of the `redis-cart` which are not needed anymore.
54+
55+
5. Apply all the updated manifests.
56+
57+
```sh
58+
kubectl apply -f ./release/updated-manifests.yaml
59+
```
60+
61+
6. **Wait for the Pods to be ready.**
62+
63+
```
64+
kubectl get pods
65+
```
66+
67+
After a few minutes, you should see:
68+
69+
```
70+
NAME READY STATUS RESTARTS AGE
71+
adservice-76bdd69666-ckc5j 1/1 Running 0 2m58s
72+
cartservice-66d497c6b7-dp5jr 1/1 Running 0 2m59s
73+
checkoutservice-666c784bd6-4jd22 1/1 Running 0 3m1s
74+
currencyservice-5d5d496984-4jmd7 1/1 Running 0 2m59s
75+
emailservice-667457d9d6-75jcq 1/1 Running 0 3m2s
76+
frontend-6b8d69b9fb-wjqdg 1/1 Running 0 3m1s
77+
loadgenerator-665b5cd444-gwqdq 1/1 Running 0 3m
78+
paymentservice-68596d6dd6-bf6bv 1/1 Running 0 3m
79+
productcatalogservice-557d474574-888kr 1/1 Running 0 3m
80+
recommendationservice-69c56b74d4-7z8r5 1/1 Running 0 3m1s
81+
shippingservice-6ccc89f8fd-v686r 1/1 Running 0 2m58s
82+
```
83+
84+
7. **Access the web frontend in a browser** using the frontend's `EXTERNAL_IP`.
85+
86+
```
87+
kubectl get service frontend-external | awk '{print $4}'
88+
```
89+
90+
**Note**- you may see `<pending>` while GCP provisions the load balancer. If this happens, wait a few minutes and re-run the command.
91+
92+
## Resources
93+
94+
- [Connecting to a Redis instance from a Google Kubernetes Engine cluster](https://cloud.google.com/memorystore/docs/redis/connect-redis-instance-gke)

docs/service-mesh.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Deploying to an Istio-enabled cluster
2+
3+
This repository provides an [`istio-manifests`](/istio-manifests) directory containing ingress resources (an Istio `Gateway` and `VirtualService`) needed to expose the app frontend running inside a Kubernetes cluster.
4+
5+
You can apply these resources to your cluster in addition to the `kubernetes-manifests`, then use the Istio IngressGateway's external IP to view the app frontend. See the following instructions for Istio steps.
6+
7+
## Steps
8+
9+
1. Create a GKE cluster with at least 4 nodes, machine type `e2-standard-4`.
10+
11+
```
12+
PROJECT_ID="<your-project-id>"
13+
ZONE="<your-GCP-zone>"
14+
15+
gcloud container clusters create onlineboutique \
16+
--project=${PROJECT_ID} --zone=${ZONE} \
17+
--machine-type=e2-standard-4 --num-nodes=4
18+
```
19+
20+
2. [Install Istio](https://istio.io/latest/docs/setup/getting-started/) on your cluster.
21+
22+
3. Enable Istio sidecar proxy injection in the `default` Kubernetes namespace.
23+
24+
```sh
25+
kubectl label namespace default istio-injection=enabled
26+
```
27+
28+
4. Apply all the manifests in the `/release` directory. This includes the Istio and Kubernetes manifests.
29+
30+
```sh
31+
kubectl apply -f ./release
32+
```
33+
34+
5. Run `kubectl get pods` to see pods are in a healthy and ready state.
35+
36+
6. Find the IP address of your Istio gateway Ingress or Service, and visit the
37+
application frontend in a web browser.
38+
39+
```sh
40+
INGRESS_HOST="$(kubectl -n istio-system get service istio-ingressgateway \
41+
-o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
42+
echo "$INGRESS_HOST"
43+
```
44+
45+
```sh
46+
curl -v "http://$INGRESS_HOST"
47+
```
48+
49+
50+
## Aditional service mesh demos using OnlineBoutique
51+
52+
- [Canary deployment](https://github.com/GoogleCloudPlatform/istio-samples/tree/master/istio-canary-gke)
53+
- [Security (mTLS, JWT, Authorization)](https://github.com/GoogleCloudPlatform/istio-samples/tree/master/security-intro)
54+
- [Cloud Operations (Stackdriver)](https://github.com/GoogleCloudPlatform/istio-samples/tree/master/istio-stackdriver)
55+
- [Stackdriver metrics (Open source Istio)](https://github.com/GoogleCloudPlatform/istio-samples/tree/master/stackdriver-metrics)
56+

docs/workload-identity.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Setup for Workload Identity clusters
2+
3+
If you have enabled [Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity) on your GKE cluster ([a requirement for Anthos Service Mesh](https://cloud.google.com/service-mesh/docs/gke-anthos-cli-new-cluster#requirements)), follow these instructions to ensure that OnlineBoutique pods can communicate with GCP APIs.
4+
5+
*Note* - These instructions have only been validated in GKE on GCP clusters. [Workload Identity is not yet supported](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#creating_a_relationship_between_ksas_and_gsas) in Anthos GKE on Prem.
6+
7+
8+
9+
1. **Set up Workload Identity** on your GKE cluster [using the instructions here](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#enable_on_new_cluster). These instructions create the Kubernetes Service Account (KSA) and Google Service Account (GSA) that the OnlineBoutique pods will use to authenticate to GCP. Take note of what Kubernetes `namespace` you use during setup.
10+
11+
2. **Add IAM Roles** to your GSA. These roles allow workload identity-enabled OnlineBoutique pods to send traces and metrics to GCP.
12+
13+
```bash
14+
PROJECT_ID=<your-gcp-project-id>
15+
GSA_NAME=<your-gsa>
16+
17+
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
18+
--member "serviceAccount:${GSA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
19+
--role roles/cloudtrace.agent
20+
21+
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
22+
--member "serviceAccount:${GSA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
23+
--role roles/monitoring.metricWriter
24+
25+
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
26+
--member "serviceAccount:${GSA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
27+
--role roles/cloudprofiler.agent
28+
29+
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
30+
--member "serviceAccount:${GSA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
31+
--role roles/clouddebugger.agent
32+
```
33+
34+
3. **Generate OnlineBoutique manifests** using your KSA as the Pod service account. In `kubernetes-manifests/`, replace `serviceAccountName: default` with the name of your KSA. (**Note** - sample below is Bash.)
35+
36+
```bash
37+
38+
KSA_NAME=<your-ksa>
39+
sed "s/serviceAccountName: default/serviceAccountName: ${KSA_NAME}/g" release/kubernetes-manifests.yaml > release/wi-kubernetes-manifests.yaml
40+
done
41+
```
42+
43+
4. **Deploy OnlineBoutique** to your GKE cluster using the install instructions above, except make sure that instead of the default namespace, you're deploying the manifests into your KSA namespace:
44+
45+
```bash
46+
NAMESPACE=<your-ksa-namespace>
47+
kubectl apply -n ${NAMESPACE} -f release/wi-kubernetes-manifests.yaml
48+
```

hack/make-docker-images.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ REPO_PREFIX="${REPO_PREFIX:?REPO_PREFIX env variable must be specified}"
2727
while IFS= read -d $'\0' -r dir; do
2828
# build image
2929
svcname="$(basename "${dir}")"
30+
builddir="${dir}"
31+
#PR 516 moved cartservice build artifacts one level down to src
32+
if [ $svcname == "cartservice" ]
33+
then
34+
builddir="${dir}/src"
35+
fi
3036
image="${REPO_PREFIX}/$svcname:$TAG"
3137
(
32-
cd "${dir}"
38+
cd "${builddir}"
3339
log "Building: ${image}"
3440
docker build -t "${image}" .
3541

hack/make-release.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ fi
4040
# update yaml
4141
"${SCRIPTDIR}"/make-release-artifacts.sh
4242

43-
# create git release / push to master
43+
# create git release / push to new branch
44+
git checkout -b "release/${TAG}"
4445
git add "${SCRIPTDIR}/../release/"
4546
git commit --allow-empty -m "Release $TAG"
46-
log "Pushing k8s manifests to master..."
47+
log "Pushing k8s manifests to release/${TAG}..."
4748
git tag "$TAG"
49+
git push --set-upstream origin "release/${TAG}"
4850
git push --tags
49-
git push origin master
5051

5152
log "Successfully tagged release $TAG."

0 commit comments

Comments
 (0)