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

Commit 4284aed

Browse files
author
Mathieu Benoit
committed
Kustomize update for OnlineBoutique
1 parent 447bcab commit 4284aed

File tree

5 files changed

+90
-85
lines changed

5 files changed

+90
-85
lines changed

content/onlineboutique/deploy-onlineboutique.md

Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,34 @@ Get the upstream Kubernetes manifests:
1616
```Bash
1717
cd ~/$ONLINE_BOUTIQUE_DIR_NAME
1818
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
19+
cd upstream
20+
kpt pkg get https://github.com/GoogleCloudPlatform/anthos-service-mesh-samples.git/docs/online-boutique-asm-manifests/base@asm-acm-tutorial
2321
```
2422

2523
## Create base overlay
2624

2725
Create Kustomize base overlay files:
2826
```Bash
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
27+
cd ~/$ONLINE_BOUTIQUE_DIR_NAME
28+
mkdir base
29+
cd base
30+
kustomize create --resources ../upstream/base/all
31+
cat <<EOF >> kustomization.yaml
4332
patchesStrategicMerge:
44-
- |-
45-
apiVersion: apps/v1
46-
kind: Deployment
47-
metadata:
48-
name: redis-cart
49-
\$patch: delete
5033
- |-
5134
apiVersion: v1
52-
kind: Service
35+
kind: Namespace
5336
metadata:
54-
name: redis-cart
55-
\$patch: delete
56-
- |-
57-
apiVersion: v1
58-
kind: Service
59-
metadata:
60-
name: frontend-external
37+
name: onlineboutique
6138
\$patch: delete
6239
EOF
6340
```
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`.
41+
{{% notice info %}}
42+
Here, we are removing the upstream `Namespace` resource as we already defined it in a previous section while configuring the associated Config Sync's `RepoSync` setup.
6643
{{% /notice %}}
6744

68-
## Define VirtualService
69-
70-
Define the `VirtualService` resource in order to establish the Ingress Gateway routing to the OnlineBoutique app:
71-
```Bash
72-
cat <<EOF > ~/$ONLINE_BOUTIQUE_DIR_NAME/base/virtual-service-frontend.yaml
45+
You could browse the files in the `~/$ONLINE_BOUTIQUE_DIR_NAME/upstream/base` folder, along with the `Namespace`, `Deployment` and `Service` resources for the OnlineBoutique apps, you could see the `VirtualService` resource which will allow to establish the Ingress Gateway routing to the OnlineBoutique app. The `spec.hosts` value is `"*"` but in the following part you will replace this value by the actual DNS of the OnlineBoutique solution (i.e. `ONLINE_BOUTIQUE_INGRESS_GATEWAY_HOST_NAME`) defined a previous section.
46+
```YAML
7347
apiVersion: networking.istio.io/v1alpha3
7448
kind: VirtualService
7549
metadata:
@@ -78,43 +52,30 @@ spec:
7852
hosts:
7953
- "*"
8054
gateways:
81-
- ${INGRESS_GATEWAY_NAMESPACE}/${INGRESS_GATEWAY_NAME}
55+
- asm-ingress/asm-ingressgateway
8256
http:
8357
- route:
8458
- destination:
8559
host: frontend
8660
port:
8761
number: 80
88-
EOF
89-
```
90-
91-
Update the Kustomize base overlay:
92-
```Bash
93-
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/base
94-
kustomize edit add resource virtual-service-frontend.yaml
9562
```
9663
9764
## Define Staging namespace overlay
9865
66+
Here are the updates for the overlay files needed to define the Staging namespace:
9967
```Bash
10068
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/staging
69+
mkdir base
70+
cd base
10171
kustomize edit add resource ../base
10272
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
73+
cp -r ../../upstream/base/for-memorystore/ .
74+
sed -i "s/REDIS_IP/${REDIS_IP}/g;s/REDIS_PORT/${REDIS_PORT}/g" for-memorystore/kustomization.yaml
75+
kustomize edit add component for-memorystore
76+
cp -r ../../upstream/base/for-virtualservice-host/ .
77+
sed -i "s/HOST_NAME/${ONLINE_BOUTIQUE_INGRESS_GATEWAY_HOST_NAME}/g" for-virtualservice-host/kustomization.yaml
78+
kustomize edit add component for-virtualservice-host
11879
```
11980

12081
## Deploy Kubernetes manifests

content/onlineboutique/set-up-authorization-policies.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ source ~/acm-workshop-variables.sh
1515
Get the upstream Kubernetes manifests:
1616
```Bash
1717
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/upstream
18-
kpt pkg get https://github.com/GoogleCloudPlatform/microservices-demo.git/docs/service-accounts@mathieu-benoit/authorization-policies
19-
rm service-accounts/Kptfile
20-
rm service-accounts/kustomization.yaml
21-
kpt pkg get https://github.com/GoogleCloudPlatform/microservices-demo.git/docs/authorization-policies@mathieu-benoit/authorization-policies
22-
rm authorization-policies/Kptfile
23-
rm authorization-policies/kustomization.yaml
18+
kpt pkg get https://github.com/GoogleCloudPlatform/anthos-service-mesh-samples.git/docs/online-boutique-asm-manifests/service-accounts@asm-acm-tutorial
19+
kpt pkg get https://github.com/GoogleCloudPlatform/anthos-service-mesh-samples.git/docs/online-boutique-asm-manifests/authorization-policies@asm-acm-tutorial
2420
```
2521

2622
## Update the Kustomize base overlay
@@ -31,10 +27,19 @@ kustomize edit add component ../upstream/service-accounts/all
3127
kustomize edit add component ../upstream/service-accounts/for-memorystore
3228
kustomize edit add component ../upstream/authorization-policies/all
3329
kustomize edit add component ../upstream/authorization-policies/for-memorystore
34-
kustomize edit add component ../upstream/authorization-policies/for-ingress-gateway
30+
```
31+
32+
## Update Staging namespace overlay
3533

36-
sed -i "s,ns/default,ns/${ONLINEBOUTIQUE_NAMESPACE},g" ../upstream/authorization-policies/all/kustomization.yaml
37-
sed -i "s,ns/default,ns/${ONLINEBOUTIQUE_NAMESPACE},g" ../upstream/authorization-policies/for-ingress-gateway/kustomization.yaml
34+
```Bash
35+
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/staging
36+
mkdir authorization-policies
37+
cp -r ../upstream/authorization-policies/for-namespace/ authorization-policies/.
38+
sed -i "s/ONLINEBOUTIQUE_NAMESPACE/${ONLINEBOUTIQUE_NAMESPACE}/g" authorization-policies/for-namespace/kustomization.yaml
39+
kustomize edit add component authorization-policies/for-namespace
40+
cp -r ../upstream/authorization-policies/for-ingress-gateway/ authorization-policies/.
41+
sed -i "s/ONLINEBOUTIQUE_NAMESPACE/${ONLINEBOUTIQUE_NAMESPACE}/g;s/INGRESS_GATEWAY_NAMESPACE/${INGRESS_GATEWAY_NAMESPACE}/g;s/INGRESS_GATEWAY_NAME/${INGRESS_GATEWAY_NAME}/g" authorization-policies/for-ingress-gateway/kustomization.yaml
42+
kustomize edit add component authorization-policies/for-ingress-gateway
3843
```
3944

4045
## Deploy Kubernetes manifests

content/onlineboutique/set-up-network-policies.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,51 @@ source ~/acm-workshop-variables.sh
1515
Get the upstream Kubernetes manifests:
1616
```Bash
1717
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/upstream
18-
kpt pkg get https://github.com/GoogleCloudPlatform/microservices-demo.git/docs/network-policies@mathieu-benoit/authorization-policies
19-
rm network-policies/Kptfile
20-
rm network-policies/kustomization.yaml
18+
kpt pkg get https://github.com/GoogleCloudPlatform/microservices-demo.git/docs/network-policies@main
19+
cd network-policies
20+
kustomize create --autodetect
21+
kustomize edit remove resource Kptfile
2122
```
2223

2324
## Update the Kustomize base overlay
2425

2526
```Bash
2627
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/base
27-
kustomize edit add component ../upstream/network-policies/all
28-
kustomize edit add component ../upstream/network-policies/for-ingress-gateway
29-
kustomize edit add component ../upstream/network-policies/for-memorystore
28+
mkdir network-policies
29+
cat <<EOF >> network-policies/kustomization.yaml
30+
apiVersion: kustomize.config.k8s.io/v1alpha1
31+
kind: Component
32+
patchesStrategicMerge:
33+
- |-
34+
apiVersion: networking.k8s.io/v1
35+
kind: NetworkPolicy
36+
metadata:
37+
name: redis-cart
38+
\$patch: delete
39+
patchesJson6902:
40+
- target:
41+
kind: NetworkPolicy
42+
name: frontend
43+
patch: |-
44+
- op: replace
45+
path: /spec/ingress
46+
value:
47+
- from:
48+
- podSelector:
49+
matchLabels:
50+
app: loadgenerator
51+
- namespaceSelector:
52+
matchLabels:
53+
name: ${INGRESS_GATEWAY_NAMESPACE}
54+
podSelector:
55+
matchLabels:
56+
app: ${INGRESS_GATEWAY_NAME}
57+
ports:
58+
- port: 8080
59+
protocol: TCP
60+
EOF
61+
kustomize edit add resources ../upstream/network-policies
62+
kustomize edit add component network-policies
3063
```
3164

3265
## Deploy Kubernetes manifests

content/onlineboutique/set-up-onlineboutique-git-repo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ roleRef:
8484
EOF
8585
```
8686
{{% notice tip %}}
87-
We are using the [`edit` user-facing role](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles) here, to follow the least privilege principle. Earlier in this workshop during the ASM installation, we extended the default `edit` role with more capabilities regarding to the Istio resources: `VirtualService`, `Sidecar` and `Authorization` wich will be leveraged in the OnlineBoutique's namespace.
87+
We are using the [`edit` user-facing role](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles) here, to follow the least privilege principle. Earlier in this workshop during the ASM installation, we extended the default `edit` role with more capabilities regarding to the Istio resources: `VirtualService`, `Sidecar` and `Authorization` which will be leveraged in the OnlineBoutique's namespace.
8888
{{% /notice %}}
8989

9090
## Deploy Kubernetes manifests

content/onlineboutique/set-up-sidecar.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,30 @@ Initialize variables:
1010
source ~/acm-workshop-variables.sh
1111
```
1212

13-
## Get upstream Kubernetes manifests
13+
## Prepare upstream Kubernetes manifests
1414

15-
Get the upstream Kubernetes manifests:
15+
Prepare the upstream Kubernetes manifests:
1616
```Bash
1717
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/upstream
18-
kpt pkg get https://github.com/GoogleCloudPlatform/microservices-demo.git/docs/sidecars@mathieu-benoit/authorization-policies
19-
rm sidecars/Kptfile
20-
rm sidecars/kustomization.yaml
18+
kpt pkg get https://github.com/GoogleCloudPlatform/anthos-service-mesh-samples.git/docs/online-boutique-asm-manifests/sidecars@asm-acm-tutorial
2119
```
2220

2321
## Update the Kustomize base overlay
2422

2523
```Bash
2624
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/base
2725
kustomize edit add component ../upstream/sidecars/all
28-
kustomize edit add component ../upstream/sidecars/for-memorystore
26+
```
27+
28+
## Update Staging namespace overlay
2929

30-
sed -i "s/default.svc.cluster.local/${ONLINEBOUTIQUE_NAMESPACE}.svc.cluster.local/g" ../upstream/sidecars/all/*
30+
```Bash
31+
cd ~/$ONLINE_BOUTIQUE_DIR_NAME/staging
32+
mkdir sidecars
33+
cp -r ../upstream/sidecars/for-namespace/ sidecars/.
34+
sed -i "s/ONLINEBOUTIQUE_NAMESPACE/${ONLINEBOUTIQUE_NAMESPACE}/g" sidecars/for-namespace/kustomization.yaml
35+
kustomize edit add component sidecars/for-namespace
36+
kustomize edit add component ../upstream/sidecars/for-memorystore
3137
```
3238

3339
## Deploy Kubernetes manifests

0 commit comments

Comments
 (0)