Skip to content

Commit

Permalink
Kustomize variation to deploy Online Boutique apps without the `grpc-…
Browse files Browse the repository at this point in the history
…health-probe` bin (#1102)

* without-grpc-health-probe-bin

* fix docker build for cartservice

* kustomize - add container-image-registry

* kustomize - add container-image-tag

* kustomize - add container-image-tag-suffix

* fix container-images-registry

* fix container-images-tag

* complete native-grpc-health-check Kustomize variation

* Review tokens in Kustomize files: $() instead of {{}} (issues with Kustomize otherwise)

* docker build -t "${image}-native-grpc"

* Bonify the custom test in Kustomize CI

* Review token to avoid issue in bash with sed: @() instead of $()

* Fix token issues with Kustomize

* More documentation for the new Kustomize variations

* fix docs

* update docs

* fix link in doc

* Fix  container-images-registry/README.md

* Update container-images-registry/README.md

* Update container-images-tag-suffix/README.md

* Update container-images-tag-suffix/README.md

* Update native-grpc-health-check/README.md

* yaml|bash|output in docs

* Remove {{ }} around REDIS_ADDR

* fix "REDIS_ADDR" token

Co-authored-by: minherz <minherz@users.noreply.github.com>
Co-authored-by: Nim Jayawardena <nimjay@google.com>
  • Loading branch information
3 people committed Oct 21, 2022
1 parent e5947e0 commit 7e7f8bb
Show file tree
Hide file tree
Showing 27 changed files with 570 additions and 59 deletions.
2 changes: 2 additions & 0 deletions hack/make-docker-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ while IFS= read -d $'\0' -r dir; do
cd "${builddir}"
log "Building: ${image}"
docker build -t "${image}" .
docker build -t "${image}-native-grpc-probes" . --target without-grpc-health-probe-bin

log "Pushing: ${image}"
docker push "${image}"
docker push "${image}-native-grpc-probes"
)
done < <(find "${SCRIPTDIR}/../src" -mindepth 1 -maxdepth 1 -type d -print0)

Expand Down
9 changes: 7 additions & 2 deletions kustomize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,19 @@ Here is the list of the variations available as Kustomize components that you co
- Changes all Online Boutique-related branding to Google Cloud's fictitious company — Cymbal Shops. The code adds/enables an environment variable `CYMBAL_BRANDING` in the `frontend` service.
- [**Integrate with Google Cloud Operations**](components/google-cloud-operations)
- Enables Monitoring (Stats), Tracing, Profiler, and Debugger for various services within Online Boutique. The code removes the existing environment variables (`DISABLE_STATS`, `DISABLE_TRACING`, `DISABLE_PROFILER`, `DISABLE_DEBUGGER`) from appropriate YAML config files.
- [**Integrate with Memorystore (redis)**](components/memorystore)
- The default Online Boutique deployment uses the in-cluster `redis` database for storing the contents of its shopping cart. The Memorystore deployment variation overrides the default database with its own Memorystore (redis) database. These changes directly affect `cartservice`.
- [**Integrate with Memorystore (Redis)**](components/memorystore)
- The default Online Boutique deployment uses the in-cluster `redis` database for storing the contents of its shopping cart. The Memorystore deployment variation overrides the default database with its own Memorystore (Redis) database. These changes directly affect `cartservice`.
- [**Integrate with Spanner**](components/spanner)
- The default Online Boutique deployment uses the in-cluster `redis` database for storing the contents of its shopping cart. The Spanner deployment variation overrides the default database with its own Spanner database. These changes directly affect `cartservice`.
- [**Secure with Network Policies**](components/network-policies)
- Deploy fine granular `NetworkPolicies` for Online Boutique.
- [**Create Kubernetes Service Accounts**](components/service-accounts)
- Deploy fine granular `ServiceAccounts` for Online Boutique.
- [**Support the native gRPC probes for Kubernetes 1.24+**](components/native-grpc-health-check)
- Deploy the Online Boutique apps by supporting the native gRPC probes for Kubernetes 1.24+.
- [**Update the registry name of the container images**](components/container-images-registry)
- [**Update the image tag of the container images**](components/container-images-tag)
- [**Add an image tag suffix to the container images**](components/container-images-tag-suffix)

### Select variations

Expand Down
28 changes: 28 additions & 0 deletions kustomize/components/container-images-registry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Update the container registry of the Online Boutique apps

By default, Online Boutique's services' container images are pulled from a public container registry (`gcr.io/google-samples/microservices-demo`). One best practice is to have these container images in your own private container registry. The Kustomize variation in this folder can help with using your own private container registry.

## Change the default container registry via Kustomize

To automate the deployment of Online Boutique integrated with your own container registry, you can leverage the following variation with [Kustomize](../..).

From the `kustomize/` folder at the root level of this repository, execute this command:
```bash
REGISTRY=my-registry # Example: gcr.io/my-project/my-directory
sed -i "s|CONTAINER_IMAGES_REGISTRY|${REGISTRY}|g" components/container-images-registry/kustomization.yaml
kustomize edit add component components/container-images-registry
```
_Note: this Kustomize component will update the container registry in the `image:` field in all `Deployments`._

This will update the `kustomize/kustomization.yaml` file which could be similar to:
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- base
components:
- components/container-images-registry
```
You can (optionally) locally render these manifests by running `kubectl kustomize .`.
You can deploy them by running `kubectl apply -k .`.
39 changes: 39 additions & 0 deletions kustomize/components/container-images-registry/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
images:
- name: gcr.io/google-samples/microservices-demo/adservice
newName: CONTAINER_IMAGES_REGISTRY/adservice
- name: gcr.io/google-samples/microservices-demo/cartservice
newName: CONTAINER_IMAGES_REGISTRY/cartservice
- name: gcr.io/google-samples/microservices-demo/checkoutservice
newName: CONTAINER_IMAGES_REGISTRY/checkoutservice
- name: gcr.io/google-samples/microservices-demo/currencyservice
newName: CONTAINER_IMAGES_REGISTRY/currencyservice
- name: gcr.io/google-samples/microservices-demo/emailservice
newName: CONTAINER_IMAGES_REGISTRY/emailservice
- name: gcr.io/google-samples/microservices-demo/frontend
newName: CONTAINER_IMAGES_REGISTRY/frontend
- name: gcr.io/google-samples/microservices-demo/loadgenerator
newName: CONTAINER_IMAGES_REGISTRY/loadgenerator
- name: gcr.io/google-samples/microservices-demo/paymentservice
newName: CONTAINER_IMAGES_REGISTRY/paymentservice
- name: gcr.io/google-samples/microservices-demo/productcatalogservice
newName: CONTAINER_IMAGES_REGISTRY/productcatalogservice
- name: gcr.io/google-samples/microservices-demo/recommendationservice
newName: CONTAINER_IMAGES_REGISTRY/recommendationservice
- name: gcr.io/google-samples/microservices-demo/shippingservice
newName: CONTAINER_IMAGES_REGISTRY/shippingservice
47 changes: 47 additions & 0 deletions kustomize/components/container-images-tag-suffix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Add a suffix to the image tag of the Online Boutique container images

You may want to add a suffix to the Online Boutique container image tag to target a specific version.
The Kustomize Component inside this folder can help.

## Add a suffix to the container image tag via Kustomize

To automate the deployment of the Online Boutique apps with a suffix added to the container imag tag, you can leverage the following variation with [Kustomize](../..).

From the `kustomize/` folder at the root level of this repository, execute this command:
```bash
SUFFIX=-my-suffix
sed -i "s/CONTAINER_IMAGES_TAG_SUFFIX/$SUFFIX/g" components/container-images-tag-suffix/kustomization.yaml
kustomize edit add component components/container-images-tag-suffix
```
_Note: this Kustomize component will add a suffix to the container image tag of the `image:` field in all `Deployments`._

This will update the `kustomize/kustomization.yaml` file which could be similar to:
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- base
components:
- components/container-images-tag-suffix
```
You can locally render these manifests by running `kubectl kustomize . | sed "s/$SUFFIX$SUFFIX/$SUFFIX/g"` as well as deploying them by running `kubectl kustomize . | sed "s/$SUFFIX$SUFFIX/$SUFFIX/g" | kubectl apply -f`.

_Note: for this variation, `kubectl apply -k .` alone won't work because there is a [known issue currently in Kustomize](https://github.com/kubernetes-sigs/kustomize/issues/4814) where the `tagSuffix` is duplicated. The `sed "s/$SUFFIX$SUFFIX/$SUFFIX/g"` commands above are a temporary workaround._

## Combine with other Kustomize Components
If you're combining this Kustomize Component with other variations, here are some considerations:
- `components/container-images-tag-suffix` should be placed before `components/container-images-registry`
- `components/container-images-tag-suffix` should be placed after `components/container-images-tag`

So for example here is the order respected:
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- base
components:
- components/container-images-tag
- components/container-images-tag-suffix
- components/container-images-registry
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
images:
- name: gcr.io/google-samples/microservices-demo/adservice
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
- name: gcr.io/google-samples/microservices-demo/cartservice
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
- name: gcr.io/google-samples/microservices-demo/checkoutservice
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
- name: gcr.io/google-samples/microservices-demo/currencyservice
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
- name: gcr.io/google-samples/microservices-demo/emailservice
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
- name: gcr.io/google-samples/microservices-demo/frontend
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
- name: gcr.io/google-samples/microservices-demo/loadgenerator
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
- name: gcr.io/google-samples/microservices-demo/paymentservice
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
- name: gcr.io/google-samples/microservices-demo/productcatalogservice
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
- name: gcr.io/google-samples/microservices-demo/recommendationservice
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
- name: gcr.io/google-samples/microservices-demo/shippingservice
tagSuffix: CONTAINER_IMAGES_TAG_SUFFIX
41 changes: 41 additions & 0 deletions kustomize/components/container-images-tag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Update the container image tag of the Online Boutique apps

By default, the Online Boutique apps are targeting the latest release version (see the list of versions [here](https://github.com/GoogleCloudPlatform/microservices-demo/releases)). You may need to change this image tag to target a specific version, this Kustomize variation will help you setting this up.

## Change the default container image tag via Kustomize

To automate the deployment of the Online Boutique apps with a specific container imag tag, you can leverage the following variation with [Kustomize](../..).

From the `kustomize/` folder at the root level of this repository, execute this command:
```bash
TAG=v1.0.0
sed -i "s/CONTAINER_IMAGES_TAG/$TAG/g" components/container-images-tag/kustomization.yaml
kustomize edit add component components/container-images-tag
```
_Note: this Kustomize component will update the container image tag of the `image:` field in all `Deployments`._

This will update the `kustomize/kustomization.yaml` file which could be similar to:
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- base
components:
- components/container-images-tag
```
You can locally render these manifests by running `kubectl kustomize .` as well as deploying them by running `kubectl apply -k .`.

**Important notes:** if combining with the other variations, here are some considerations:
- should be placed before `components/container-images-registry`

So for example here is the order respected:
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- base
components:
- components/container-images-tag
- components/container-images-registry
```
39 changes: 39 additions & 0 deletions kustomize/components/container-images-tag/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
images:
- name: gcr.io/google-samples/microservices-demo/adservice
newTag: CONTAINER_IMAGES_TAG
- name: gcr.io/google-samples/microservices-demo/cartservice
newTag: CONTAINER_IMAGES_TAG
- name: gcr.io/google-samples/microservices-demo/checkoutservice
newTag: CONTAINER_IMAGES_TAG
- name: gcr.io/google-samples/microservices-demo/currencyservice
newTag: CONTAINER_IMAGES_TAG
- name: gcr.io/google-samples/microservices-demo/emailservice
newTag: CONTAINER_IMAGES_TAG
- name: gcr.io/google-samples/microservices-demo/frontend
newTag: CONTAINER_IMAGES_TAG
- name: gcr.io/google-samples/microservices-demo/loadgenerator
newTag: CONTAINER_IMAGES_TAG
- name: gcr.io/google-samples/microservices-demo/paymentservice
newTag: CONTAINER_IMAGES_TAG
- name: gcr.io/google-samples/microservices-demo/productcatalogservice
newTag: CONTAINER_IMAGES_TAG
- name: gcr.io/google-samples/microservices-demo/recommendationservice
newTag: CONTAINER_IMAGES_TAG
- name: gcr.io/google-samples/microservices-demo/shippingservice
newTag: CONTAINER_IMAGES_TAG
8 changes: 4 additions & 4 deletions kustomize/components/cymbal-branding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ But you may want to use Google Cloud's fictitious company, _Cymbal Shops_, inste

To use "Cymbal Shops" branding, set the `CYMBAL_BRANDING` environment variable to `"true"` in the the Kubernetes manifest (`.yaml`) for the `frontend` Deployment.

```
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -29,12 +29,12 @@ spec:
To automate the deployment of Online Boutique with the Cymbal Shops branding you can leverage the following variation with [Kustomize](../..).
From the `kustomize/` folder at the root level of this repository, execute this command:
```
kustomize edit add components/cymbal-branding
```bash
kustomize edit add component components/cymbal-branding
```

This will update the `kustomize/kustomization.yaml` file which could be similar to:
```
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
Expand Down
10 changes: 5 additions & 5 deletions kustomize/components/google-cloud-operations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ By default, [Google Cloud Operations](https://cloud.google.com/products/operatio

You can see the instrumentation status in your deployment by opening one of the `Deployment` YAML files and seeing:

```YAML
```yaml
- name: DISABLE_STATS
value: "1"
- name: DISABLE_TRACING
Expand All @@ -31,7 +31,7 @@ value: "0"
</del>

You will also need to make sure that you have the associated Google APIs enabled in your Google Cloud project:
```
```bash
gcloud services enable \
monitoring.googleapis.com \
cloudtrace.googleapis.com \
Expand Down Expand Up @@ -67,12 +67,12 @@ gcloud projects add-iam-policy-binding ${PROJECT_ID} \
To automate the deployment of Online Boutique integrated with Google Cloud Operations you can leverage the following variation with [Kustomize](../..).

From the `kustomize/` folder at the root level of this repository, execute this command:
```
kustomize edit add components/google-cloud-operations
```bash
kustomize edit add component components/google-cloud-operations
```

This will update the `kustomize/kustomization.yaml` file which could be similar to:
```
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
Expand Down
6 changes: 3 additions & 3 deletions kustomize/components/memorystore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ _Note: You can also find in this repository the Terraform script to provision th
To automate the deployment of Online Boutique integrated with Memorystore (Redis) you can leverage the following variation with [Kustomize](../..).

From the `kustomize/` folder at the root level of this repository, execute this command:
```bash
kustomize edit add components/memorystore
```
kustomize edit add component components/memorystore
```
_Note: this Kustomize component will also remove the `redis-cart` `Deployment` and `Service` not used anymore._

Expand All @@ -50,7 +50,7 @@ Update current Kustomize manifest to target this Memorystore (Redis) instance.
```bash
REDIS_IP=$(gcloud redis instances describe redis-cart --region=${REGION} --format='get(host)')
REDIS_PORT=$(gcloud redis instances describe redis-cart --region=${REGION} --format='get(port)')
sed -i "s/{{REDIS_ADDR}}/${REDIS_IP}:${REDIS_PORT}/g" components/memorystore/kustomization.yaml
sed -i "s/\"REDIS_ADDR\"/${REDIS_IP}:${REDIS_PORT}/g" components/memorystore/kustomization.yaml
```

You can locally render these manifests by running `kubectl kustomize .` as well as deploying them by running `kubectl apply -k .`.
Expand Down
2 changes: 1 addition & 1 deletion kustomize/components/memorystore/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ patchesStrategicMerge:
- name: server
env:
- name: REDIS_ADDR
value: "{{REDIS_ADDR}}"
value: "REDIS_ADDR"
# redis - remove the redis-cart Deployment
- |-
apiVersion: apps/v1
Expand Down
Loading

0 comments on commit 7e7f8bb

Please sign in to comment.