Initial commit
Some checks failed
Continuous Integration - Pull Request / code-tests (pull_request) Has been cancelled
Continuous Integration - Pull Request / deployment-tests (local-code) (pull_request) Has been cancelled
helm-chart-ci / helm-chart-ci (pull_request) Has been cancelled
kubevious-manifests-ci / kubevious-manifests-ci (pull_request) Has been cancelled
kustomize-build-ci / kustomize-build-ci (pull_request) Has been cancelled
terraform-validate-ci / terraform-validate-ci (pull_request) Has been cancelled
Clean up deployment / cleanup-namespace (pull_request) Has been cancelled
Continuous Integration - Main/Release / code-tests (push) Has been cancelled
Continuous Integration - Main/Release / deployment-tests (local-code) (push) Has been cancelled
helm-chart-ci / helm-chart-ci (push) Has been cancelled
kubevious-manifests-ci / kubevious-manifests-ci (push) Has been cancelled
kustomize-build-ci / kustomize-build-ci (push) Has been cancelled
terraform-validate-ci / terraform-validate-ci (push) Has been cancelled
Some checks failed
Continuous Integration - Pull Request / code-tests (pull_request) Has been cancelled
Continuous Integration - Pull Request / deployment-tests (local-code) (pull_request) Has been cancelled
helm-chart-ci / helm-chart-ci (pull_request) Has been cancelled
kubevious-manifests-ci / kubevious-manifests-ci (pull_request) Has been cancelled
kustomize-build-ci / kustomize-build-ci (pull_request) Has been cancelled
terraform-validate-ci / terraform-validate-ci (pull_request) Has been cancelled
Clean up deployment / cleanup-namespace (pull_request) Has been cancelled
Continuous Integration - Main/Release / code-tests (push) Has been cancelled
Continuous Integration - Main/Release / deployment-tests (local-code) (push) Has been cancelled
helm-chart-ci / helm-chart-ci (push) Has been cancelled
kubevious-manifests-ci / kubevious-manifests-ci (push) Has been cancelled
kustomize-build-ci / kustomize-build-ci (push) Has been cancelled
terraform-validate-ci / terraform-validate-ci (push) Has been cancelled
This commit is contained in:
67
kustomize/components/memorystore/README.md
Normal file
67
kustomize/components/memorystore/README.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Integrate Online Boutique with Memorystore (Redis)
|
||||
|
||||
By default the `cartservice` app is serializing the data in an in-cluster Redis database. Using a database outside your GKE cluster could bring more resiliency and more security with a managed service like Google Cloud Memorystore (Redis).
|
||||
|
||||

|
||||
|
||||
## Provision a Memorystore (Redis) instance
|
||||
|
||||
Important notes:
|
||||
|
||||
- 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.
|
||||
- You cannot connect to a Memorystore (Redis) instance from a GKE cluster without VPC-native/IP aliasing enabled.
|
||||
|
||||
To provision a Memorystore (Redis) instance you can follow the following instructions:
|
||||
|
||||
```bash
|
||||
ZONE="<your-GCP-zone>"
|
||||
REGION="<your-GCP-region>"
|
||||
|
||||
gcloud services enable redis.googleapis.com
|
||||
|
||||
gcloud redis instances create redis-cart \
|
||||
--size=1 \
|
||||
--region=${REGION} \
|
||||
--zone=${ZONE} \
|
||||
--redis-version=redis_7_0
|
||||
```
|
||||
|
||||
_Note: You can also find in this repository the Terraform script to provision the Memorystore (Redis) instance alongside the GKE cluster, more information [here](/terraform)._
|
||||
|
||||
## Deploy Online Boutique connected to a Memorystore (Redis) instance
|
||||
|
||||
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 component components/memorystore
|
||||
```
|
||||
|
||||
_Note: this Kustomize component will also remove the `redis-cart` `Deployment` and `Service` not used anymore._
|
||||
|
||||
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/memorystore
|
||||
```
|
||||
|
||||
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_CONNECTION_STRING/${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 .`.
|
||||
|
||||
## Resources
|
||||
|
||||
- [Connecting to a Redis instance from a Google Kubernetes Engine cluster](https://cloud.google.com/memorystore/docs/redis/connect-redis-instance-gke)
|
||||
- [Seamlessly encrypt traffic from any apps in your Mesh to Memorystore (Redis)](https://medium.com/google-cloud/64b71969318d)
|
||||
45
kustomize/components/memorystore/kustomization.yaml
Normal file
45
kustomize/components/memorystore/kustomization.yaml
Normal file
@@ -0,0 +1,45 @@
|
||||
# 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
|
||||
patches:
|
||||
# cartservice - replace REDIS_ADDR to target new Memorystore (redis) instance
|
||||
- patch: |-
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: cartservice
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: server
|
||||
env:
|
||||
- name: REDIS_ADDR
|
||||
value: "REDIS_CONNECTION_STRING"
|
||||
# redis - remove the redis-cart Deployment
|
||||
- patch: |-
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: redis-cart
|
||||
$patch: delete
|
||||
# redis - remove the redis-cart Service
|
||||
- patch: |-
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: redis-cart
|
||||
$patch: delete
|
||||
Reference in New Issue
Block a user