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

Commit 2931f5b

Browse files
author
Mathieu Benoit
committed
Review Online Boutique flow
1 parent 7a4f6c8 commit 2931f5b

File tree

9 files changed

+151
-197
lines changed

9 files changed

+151
-197
lines changed

content/onlineboutique/deploy-apps.md

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,83 @@
11
---
22
title: "Deploy apps"
3-
weight: 4
3+
weight: 5
44
description: "Duration: 5 min | Persona: Apps Operator"
55
tags: ["apps-operator", "asm"]
66
---
77
![Apps Operator](/images/apps-operator.png)
88
_{{< param description >}}_
99

10-
In this section, you will deploy via Kustomize the Online Boutique apps in the dedicated namespace.
10+
In this section, you will deploy the Online Boutique apps.
1111

1212
Initialize variables:
1313
```Bash
1414
WORK_DIR=~/
1515
source ${WORK_DIR}acm-workshop-variables.sh
1616
```
1717

18-
## Get upstream Kubernetes manifests
18+
## Update base overlay
1919

20-
Get the upstream Kubernetes manifests:
20+
Update the Kustomize base overlay:
2121
```Bash
22-
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME
23-
mkdir upstream
24-
cd upstream
25-
kpt pkg get https://github.com/GoogleCloudPlatform/anthos-service-mesh-samples.git/docs/online-boutique-asm-manifests/base@main
26-
```
27-
28-
## Create base overlay
29-
30-
Create Kustomize base overlay files:
31-
```Bash
32-
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME
33-
mkdir base
34-
cd base
35-
kustomize create --resources ../upstream/base/all
36-
cat <<EOF >> kustomization.yaml
22+
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/base
23+
kustomize edit add resource ../upstream/base
24+
cat <<EOF >> ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/base/kustomization.yaml
3725
patchesStrategicMerge:
3826
- |-
3927
apiVersion: v1
40-
kind: Namespace
28+
kind: Service
4129
metadata:
42-
name: onlineboutique
30+
name: frontend-external
4331
\$patch: delete
4432
EOF
4533
```
4634
{{% notice info %}}
47-
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.
35+
Here we are deleting the `Service` `frontend-external` because the `frontend` app will be exposed by the Ingress Gateway.
4836
{{% /notice %}}
4937

50-
You could browse the files in the `${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/upstream/base` folder, along with the `Namespace`, `Deployment` and `Service` 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 in a previous section.
38+
## Define VirtualService
5139

52-
## Define Staging namespace overlay
40+
Define the `VirtualService` resource in order to establish the Ingress Gateway routing to the Online Boutique apps:
41+
```Bash
42+
cat <<EOF > ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/base/virtualservice.yaml
43+
apiVersion: networking.istio.io/v1alpha3
44+
kind: VirtualService
45+
metadata:
46+
name: frontend
47+
spec:
48+
hosts:
49+
- "*"
50+
gateways:
51+
- ${INGRESS_GATEWAY_NAMESPACE}/${INGRESS_GATEWAY_NAME}
52+
http:
53+
- route:
54+
- destination:
55+
host: frontend
56+
port:
57+
number: 80
58+
EOF
59+
```
5360

54-
Update the overlay files needed to define the Staging namespace:
61+
Update the Kustomize base overlay:
5562
```Bash
56-
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/staging
57-
kustomize edit add resource ../base
58-
kustomize edit set namespace $ONLINEBOUTIQUE_NAMESPACE
59-
cp -r ../upstream/base/for-virtualservice-host/ .
60-
sed -i "s/HOST_NAME/${ONLINE_BOUTIQUE_INGRESS_GATEWAY_HOST_NAME}/g" for-virtualservice-host/kustomization.yaml
61-
kustomize edit add component for-virtualservice-host
63+
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/base
64+
kustomize edit add resource virtualservice.yaml
6265
```
6366

64-
Update the `Deployments`'s container images to point to the private Artifact Registry:
67+
## Update the Staging namespace overlay
68+
69+
Update the Staging Kustomize overlay with the proper `hosts` value in the `VirtualService` and with the `Deployments`'s container images to point to the private Artifact Registry:
6570
```Bash
66-
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/staging
6771
cat <<EOF >> ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/staging/kustomization.yaml
6872
patchesJson6902:
73+
- target:
74+
kind: VirtualService
75+
name: frontend
76+
patch: |-
77+
- op: replace
78+
path: /spec/hosts
79+
value:
80+
- ${ONLINE_BOUTIQUE_INGRESS_GATEWAY_HOST_NAME}
6981
- target:
7082
kind: Deployment
7183
name: adservice
@@ -166,37 +178,36 @@ git add . && git commit -m "Online Boutique apps" && git push origin main
166178
## Check deployments
167179

168180
List the Kubernetes resources managed by Config Sync in **GKE cluster** for the **Online Boutique apps** repository:
181+
{{< tabs groupId="cs-status-ui">}}
182+
{{% tab name="gcloud" %}}
169183
```Bash
170184
gcloud alpha anthos config sync repo describe \
171185
--project $TENANT_PROJECT_ID \
172186
--managed-resources all \
173187
--sync-name repo-sync \
174188
--sync-namespace $ONLINEBOUTIQUE_NAMESPACE
175189
```
176-
Wait and re-run this command above until you see `"status": "SYNCED"`. All the `managed_resources` listed should have `STATUS: Current` as well.
177-
178-
List the GitHub runs for the **Online Boutique apps** repository:
190+
Wait and re-run this command above until you see `"status": "SYNCED"`.
191+
{{% /tab %}}
192+
{{% tab name="UI" %}}
193+
Alternatively, you could also see this from within the Cloud Console, by clicking on this link:
179194
```Bash
180-
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME && gh run list
195+
echo -e "https://console.cloud.google.com/kubernetes/config_management/status?clusterName=${GKE_NAME}&id=${GKE_NAME}&project=${TENANT_PROJECT_ID}"
181196
```
197+
Wait until you see the `Sync status` column as `SYNCED`. And then you can also click on `View resources` to see the details.
198+
{{% /tab %}}
199+
{{< /tabs >}}
182200

183201
## Check the Online Boutique apps
184202

185-
Navigate to the Online Boutique apps, click on the link displayed by the command below:
186-
```Bash
187-
echo -e "https://${ONLINE_BOUTIQUE_INGRESS_GATEWAY_HOST_NAME}"
188-
```
189-
190-
You will see that the Online Boutique website is not working.
191-
192-
Open the list of the **Workloads** deployed in the GKE cluster, click on the link displayed by the command below:
203+
Open the list of the **Workloads** deployed in the GKE cluster, you will see that the Online Boutique apps is successfully deployed. Click on the link displayed by the command below:
193204
```Bash
194205
echo -e "https://console.cloud.google.com/kubernetes/workload/overview?project=${TENANT_PROJECT_ID}"
195206
```
196207

197-
Here you could see that all the Online Boutique `Deployments` are in `Error`. If you look at more details on the `Pods` you will see this error:
198-
```Plaintext
199-
Readiness probe failed: Get "http://10.4.2.13:15020/app-health/server/readyz": dial tcp 10.4.2.13:15020: connect: connection refused
208+
Navigate to the Online Boutique apps, click on the link displayed by the command below:
209+
```Bash
210+
echo -e "https://${ONLINE_BOUTIQUE_INGRESS_GATEWAY_HOST_NAME}"
200211
```
201212

202-
At this stage, that's expected because we have deployed the `deny-all` `NetworkPolicy` in the `onlineboutique` `Namespace` blocking any ingress and egress requests to and from any app in this `Namespace`. We will fix this in the next sections.
213+
You should receive the error: `RBAC: access denied`. This is because the default deny-all `AuthorizationPolicy` has been applied to the entire mesh. In the next section you will apply a fine granular `AuthorizationPolicy` for the Online Boutique apps in order to get fix this.

content/onlineboutique/deploy-authorization-policies.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: "Deploy AuthorizationPolicies"
3-
weight: 7
3+
weight: 6
44
description: "Duration: 5 min | Persona: Apps Operator"
55
tags: ["apps-operator", "asm", "security-tips"]
66
---
77
![Apps Operator](/images/apps-operator.png)
88
_{{< param description >}}_
99

10-
In this section, you will deploy granular and specific `AuthorizationPolicies` for the Online Boutique namespace. At the end that's where you will finally have a working Whereami app :)
10+
In this section, you will deploy granular and specific `AuthorizationPolicies` for the Online Boutique namespace. At the end that's where you will finally have working Online Boutique apps :)
1111

1212
Initialize variables:
1313
```Bash
@@ -20,15 +20,14 @@ source ${WORK_DIR}acm-workshop-variables.sh
2020
Get the upstream Kubernetes manifests:
2121
```Bash
2222
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/upstream
23-
kpt pkg get https://github.com/GoogleCloudPlatform/anthos-service-mesh-samples.git/docs/online-boutique-asm-manifests/service-accounts@main
2423
kpt pkg get https://github.com/GoogleCloudPlatform/anthos-service-mesh-samples.git/docs/online-boutique-asm-manifests/authorization-policies@main
2524
```
2625

2726
## Update the Kustomize base overlay
2827

2928
```Bash
3029
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/base
31-
kustomize edit add component ../upstream/service-accounts/all
30+
kustomize edit add component ../upstream/components/service-accounts
3231
kustomize edit add component ../upstream/authorization-policies/all
3332
```
3433

@@ -55,18 +54,36 @@ git add . && git commit -m "Online Boutique AuthorizationPolicies" && git push o
5554
## Check deployments
5655

5756
List the Kubernetes resources managed by Config Sync in **GKE cluster** for the **Online Boutique apps** repository:
57+
{{< tabs groupId="cs-status-ui">}}
58+
{{% tab name="gcloud" %}}
5859
```Bash
5960
gcloud alpha anthos config sync repo describe \
6061
--project $TENANT_PROJECT_ID \
6162
--managed-resources all \
6263
--sync-name repo-sync \
6364
--sync-namespace $ONLINEBOUTIQUE_NAMESPACE
6465
```
65-
Wait and re-run this command above until you see `"status": "SYNCED"`. All the `managed_resources` listed should have `STATUS: Current` as well.
66+
Wait and re-run this command above until you see `"status": "SYNCED"`.
67+
{{% /tab %}}
68+
{{% tab name="UI" %}}
69+
Alternatively, you could also see this from within the Cloud Console, by clicking on this link:
70+
```Bash
71+
echo -e "https://console.cloud.google.com/kubernetes/config_management/status?clusterName=${GKE_NAME}&id=${GKE_NAME}&project=${TENANT_PROJECT_ID}"
72+
```
73+
Wait until you see the `Sync status` column as `SYNCED`. And then you can also click on `View resources` to see the details.
74+
{{% /tab %}}
75+
{{< /tabs >}}
6676

6777
List the GitHub runs for the **Online Boutique apps** repository:
6878
```Bash
6979
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME && gh run list
7080
```
7181

82+
## Check the Online Boutique apps
83+
84+
Navigate to the Online Boutique apps, click on the link displayed by the command below:
85+
```Bash
86+
echo -e "https://${ONLINE_BOUTIQUE_INGRESS_GATEWAY_HOST_NAME}"
87+
```
88+
7289
You should now have the Online Boutique apps working successfully. Congrats!

content/onlineboutique/deploy-network-policies.md

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: "Deploy NetworkPolicies"
3-
weight: 6
3+
weight: 3
44
description: "Duration: 5 min | Persona: Apps Operator"
55
tags: ["apps-operator", "security-tips"]
66
---
77
![Apps Operator](/images/apps-operator.png)
88
_{{< param description >}}_
99

10-
In this section, you will deploy granular and specific `NetworkPolicies` for the Online Boutique namespace. This will fix the policies violation you faced earlier. At the end you will catch another issue that you will resolve in the next section.
10+
In this section, you will deploy granular and specific `NetworkPolicies` for the Online Boutique namespace. This will fix the policies violation you faced earlier.
1111

1212
Initialize variables:
1313
```Bash
@@ -19,16 +19,16 @@ source ${WORK_DIR}acm-workshop-variables.sh
1919

2020
Get the upstream Kubernetes manifests:
2121
```Bash
22-
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/upstream
23-
kpt pkg get https://github.com/GoogleCloudPlatform/microservices-demo.git/docs/network-policies@main
24-
cd network-policies
25-
kustomize create --autodetect
26-
kustomize edit remove resource Kptfile
22+
kpt pkg get https://github.com/GoogleCloudPlatform/microservices-demo.git/kustomize@main ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/upstream
23+
rm ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/upstream/tests -rf
24+
rm ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/upstream/Kptfile
25+
rm ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/upstream/kustomization.yaml
2726
```
2827

2928
## Update the Kustomize base overlay
3029

3130
```Bash
31+
mkdir ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/base
3232
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/base
3333
mkdir network-policies
3434
cat <<EOF >> network-policies/kustomization.yaml
@@ -56,10 +56,22 @@ patchesJson6902:
5656
- port: 8080
5757
protocol: TCP
5858
EOF
59-
kustomize edit add resource ../upstream/network-policies
59+
kustomize create
60+
kustomize edit add component ../upstream/components/network-policies
6061
kustomize edit add component network-policies
6162
```
6263

64+
## Define Staging namespace overlay
65+
66+
```Bash
67+
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME/staging
68+
kustomize edit add resource ../base
69+
kustomize edit set namespace $ONLINEBOUTIQUE_NAMESPACE
70+
```
71+
{{% notice info %}}
72+
The `kustomization.yaml` file was already existing from the [GitHub repository template](https://github.com/mathieu-benoit/config-sync-app-template-repo/blob/main/staging/kustomization.yaml) used when we created the **Online Boutique apps** repository.
73+
{{% /notice %}}
74+
6375
## Deploy Kubernetes manifests
6476

6577
```Bash
@@ -70,30 +82,38 @@ git add . && git commit -m "Online Boutique NetworkPolicies" && git push origin
7082
## Check deployments
7183

7284
List the Kubernetes resources managed by Config Sync in **GKE cluster** for the **Online Boutique apps** repository:
85+
{{< tabs groupId="cs-status-ui">}}
86+
{{% tab name="gcloud" %}}
7387
```Bash
7488
gcloud alpha anthos config sync repo describe \
7589
--project $TENANT_PROJECT_ID \
7690
--managed-resources all \
7791
--sync-name repo-sync \
7892
--sync-namespace $ONLINEBOUTIQUE_NAMESPACE
7993
```
80-
Wait and re-run this command above until you see `"status": "SYNCED"`. All the `managed_resources` listed should have `STATUS: Current` as well.
81-
82-
List the GitHub runs for the **Online Boutique apps** repository:
94+
Wait and re-run this command above until you see `"status": "SYNCED"`.
95+
{{% /tab %}}
96+
{{% tab name="UI" %}}
97+
Alternatively, you could also see this from within the Cloud Console, by clicking on this link:
8398
```Bash
84-
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME && gh run list
99+
echo -e "https://console.cloud.google.com/kubernetes/config_management/status?clusterName=${GKE_NAME}&id=${GKE_NAME}&project=${TENANT_PROJECT_ID}"
85100
```
101+
Wait until you see the `Sync status` column as `SYNCED`. And then you can also click on `View resources` to see the details.
102+
{{% /tab %}}
103+
{{< /tabs >}}
86104

87-
## Check the Online Boutique apps
88-
89-
Open the list of the **Workloads** deployed in the GKE cluster, you will now see that all the Online Boutique apps are working. Click on the link displayed by the command below:
105+
The `namespaces-required-networkpolicies` `Constraint` shouldn't complain anymore. Click on the link displayed by the command below:
90106
```Bash
91-
echo -e "https://console.cloud.google.com/kubernetes/workload/overview?project=${TENANT_PROJECT_ID}"
107+
echo -e "https://console.cloud.google.com/kubernetes/object/constraints.gatekeeper.sh/k8srequirenamespacenetworkpolicies/${GKE_LOCATION}/${GKE_NAME}/namespaces-required-networkpolicies?apiVersion=v1beta1&project=${TENANT_PROJECT_ID}"
92108
```
93109

94-
Navigate to the Online Boutique apps, click on the link displayed by the command below:
95-
```Bash
96-
echo -e "https://${ONLINE_BOUTIQUE_INGRESS_GATEWAY_HOST_NAME}"
110+
At the very bottom of the object's description you should now see:
111+
```Plaintext
112+
...
113+
totalViolations: 0
97114
```
98115

99-
You should receive the error: `RBAC: access denied`. This is because the default deny-all `AuthorizationPolicy` has been applied to the entire mesh. In the next section you will apply fine granular `AuthorizationPolicies` for the Online Boutique apps in order to get them working.
116+
List the GitHub runs for the **Online Boutique apps** repository:
117+
```Bash
118+
cd ${WORK_DIR}$ONLINE_BOUTIQUE_DIR_NAME && gh run list
119+
```

0 commit comments

Comments
 (0)