Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit 53755c3

Browse files
author
Mathieu Benoit
authored
Merge pull request #29 from mathieu-benoit/onlineboutique-kustomize
`Kustomize` support for OnlineBoutique
2 parents bf52bed + 44cb0c4 commit 53755c3

File tree

6 files changed

+130
-825
lines changed

6 files changed

+130
-825
lines changed

content/onlineboutique/deploy-onlineboutique.md

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,71 @@ source ~/acm-workshop-variables.sh
1212

1313
## Get upstream Kubernetes manifests
1414

15-
Create a dedicated folder for the Online Boutique sample apps in the GKE configs's Git repo:
15+
Get the upstream Kubernetes manifests:
1616
```Bash
17-
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/config-sync
18-
curl https://raw.githubusercontent.com/GoogleCloudPlatform/microservices-demo/main/release/kubernetes-manifests.yaml > tmp.yaml
19-
nomos hydrate --path . --output . --no-api-server-check --source-format unstructured
20-
rm tmp.yaml
17+
cd ~/$ONLINE_BOUTIQUE_DIR_NAME
18+
mkdir upstream
19+
mkdir upstream/base
20+
curl https://raw.githubusercontent.com/GoogleCloudPlatform/microservices-demo/main/release/kubernetes-manifests.yaml > upstream/base/kubernetes-manifests.yaml
21+
cd upstream/base
22+
kustomize create --resources kubernetes-manifests.yaml
2123
```
2224

23-
## Update Kubernetes manifests
25+
## Create base overlay
2426

25-
Cleanup and update the upstream files:
27+
Create Kustomize base overlay files:
2628
```Bash
27-
rm service_redis-cart.yaml
28-
rm deployment_redis-cart.yaml
29-
rm service_frontend-external.yaml
30-
kpt fn eval . \
31-
-i set-namespace:v0.2 \
32-
-- namespace=$ONLINEBOUTIQUE_NAMESPACE
33-
sed -i "s/redis-cart:6379/$REDIS_IP:$REDIS_PORT/g" ~/$ONLINE_BOUTIQUE_DIR_NAME/config-sync/deployment_cartservice.yaml
29+
mkdir ~/$ONLINE_BOUTIQUE_DIR_NAME/base
30+
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/base
31+
kustomize create --resources ../upstream/base
32+
cat <<EOF >> ~/$ONLINE_BOUTIQUE_DIR_NAME/base/kustomization.yaml
33+
patchesJson6902:
34+
- target:
35+
kind: Deployment
36+
name: cartservice
37+
patch: |-
38+
- op: replace
39+
path: /spec/template/spec/containers/0/env/0
40+
value:
41+
name: REDIS_ADDR
42+
value: $REDIS_IP:$REDIS_PORT
43+
patchesStrategicMerge:
44+
- |-
45+
apiVersion: apps/v1
46+
kind: Deployment
47+
metadata:
48+
name: redis-cart
49+
\$patch: delete
50+
- |-
51+
apiVersion: v1
52+
kind: Service
53+
metadata:
54+
name: redis-cart
55+
\$patch: delete
56+
- |-
57+
apiVersion: v1
58+
kind: Service
59+
metadata:
60+
name: frontend-external
61+
\$patch: delete
62+
EOF
3463
```
64+
{{% notice note %}}
65+
Here we are removing the `redis-cart` `Deployment` and `Service` because we are leveraging Memorystore (redis) instead. We are also removing the default `frontend-external` `Service` because we will use the ASM Ingress Gateway to expose the Online Boutique's `frontend`.
66+
{{% /notice %}}
3567

3668
## Define VirtualService
3769

70+
Define the `VirtualService` resource in order to establish the Ingress Gateway routing to the OnlineBoutique app:
3871
```Bash
39-
cat <<EOF > ~/$ONLINE_BOUTIQUE_DIR_NAME/config-sync/virtualservice_frontend.yaml
72+
cat <<EOF > ~/$ONLINE_BOUTIQUE_DIR_NAME/base/virtual-service-frontend.yaml
4073
apiVersion: networking.istio.io/v1alpha3
4174
kind: VirtualService
4275
metadata:
4376
name: frontend
44-
namespace: ${ONLINEBOUTIQUE_NAMESPACE}
4577
spec:
4678
hosts:
47-
- ${ONLINE_BOUTIQUE_INGRESS_GATEWAY_HOST_NAME}
79+
- "*"
4880
gateways:
4981
- ${INGRESS_GATEWAY_NAMESPACE}/${INGRESS_GATEWAY_NAME}
5082
http:
@@ -56,6 +88,35 @@ spec:
5688
EOF
5789
```
5890

91+
Update the Kustomize base overlay:
92+
```Bash
93+
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/base
94+
kustomize edit add resource virtual-service-frontend.yaml
95+
```
96+
97+
## Define Staging namespace overlay
98+
99+
```Bash
100+
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/staging
101+
kustomize edit add resource ../base
102+
kustomize edit set namespace $ONLINEBOUTIQUE_NAMESPACE
103+
```
104+
105+
Update the Kustomize base overlay in order to set proper `hosts` value in the `VirtualService` resource:
106+
```Bash
107+
cat <<EOF >> ~/$ONLINE_BOUTIQUE_DIR_NAME/staging/kustomization.yaml
108+
patchesJson6902:
109+
- target:
110+
kind: VirtualService
111+
name: frontend
112+
patch: |-
113+
- op: replace
114+
path: /spec/hosts
115+
value:
116+
- ${ONLINE_BOUTIQUE_INGRESS_GATEWAY_HOST_NAME}
117+
EOF
118+
```
119+
59120
## Deploy Kubernetes manifests
60121

61122
```Bash

0 commit comments

Comments
 (0)