Skip to content

Commit 9c30656

Browse files
committed
part 5 edits
1 parent 26b7147 commit 9c30656

9 files changed

+99
-67
lines changed

5-hosted-resources/bigquery/helloworld-dataset.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@ apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
22
kind: BigQueryDataset
33
metadata:
44
name: helloworld
5-
annotations:
6-
configsync.gke.io/cluster-name-selector: cymbal-admin
75
spec:
86
friendlyName: hello-world

5-hosted-resources/bigquery/mock-dataset.yaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
22
kind: BigQueryJob
33
metadata:
44
name: cymbal-mock-load-job
5-
annotations:
6-
configsync.gke.io/cluster-name-selector: cymbal-admin
75
spec:
86
location: "US"
97
jobTimeoutMs: "600000"
108
load:
119
sourceUris:
12-
- "gs://PROJECT_ID/cymbal-mock-transactions.csv"
10+
- "gs://krm-test11/cymbal-mock-transactions.csv"
1311
destinationTable:
1412
tableRef:
1513
name: cymbalmocktable
@@ -32,17 +30,13 @@ apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
3230
kind: BigQueryDataset
3331
metadata:
3432
name: cymbalmockdataset
35-
annotations:
36-
configsync.gke.io/cluster-name-selector: cymbal-admin
3733
spec:
3834
friendlyName: cymbal-mock-dataset
3935
---
4036
apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
4137
kind: BigQueryTable
4238
metadata:
4339
name: cymbalmocktable
44-
annotations:
45-
configsync.gke.io/cluster-name-selector: cymbal-admin
4640
spec:
4741
friendlyName: cymbal-mock-table
4842
datasetRef:

5-hosted-resources/configconnector.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ metadata:
55
name: configconnector.core.cnrm.cloud.google.com
66
spec:
77
mode: cluster
8-
googleServiceAccount: "cymbal-admin-kcc@PROJECT_ID.iam.gserviceaccount.com"
8+
googleServiceAccount: "cymbal-admin-kcc@krm-test11.iam.gserviceaccount.com"

5-hosted-resources/partA-config-connector.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ Expected output:
5959
✅ Finished installing Config Connector on all clusters.
6060
```
6161

62-
This script grants Config Connector (running in the GKE cluster) the IAM permissions it needs to create and update GCP resources in your project, and deploys Config Connector onto the cluster.
62+
This script does the following:
63+
1. Uninstalls Config Sync from the `cymbal-admin` cluster. (**Note** - currently a bug causes Config Sync and Config Connector to conflict with each other. In the future, you will be able to use Config Sync to deploy your Config Connector resources)
64+
2. Grants Config Connector IAM permissions to lifecycle GCP resources in your project
65+
3. Installs Config Connector on the `cymbal-admin` cluster.
66+
67+
grants Config Connector (running in the GKE cluster) the IAM permissions it needs to create and update GCP resources in your project, and deploys Config Connector onto the cluster.
6368

6469
### 5. **Verify that Config Connector is installed on the admin cluster.**
6570

@@ -86,6 +91,7 @@ Let's start with a basic example of creating a GCP-hosted resource using Config
8691
![screenshot](screenshots/secadmin-gce.jpg)
8792

8893

94+
8995
### 1. **View the GCE KRM resources.**
9096

9197
```
@@ -119,7 +125,7 @@ spec:
119125

120126
This KRM resource defines one Compute Engine instance, along with a Compute Disk and some networking resources. Notice how the KRM looks a lot like a Deployment YAML - it has a name, metadata with some labels, and a spec, with info specifically about a GCE instance. Config Connector knows how to read this `ComputeEngine` resource type, and take action on it - in this case, create a Compute Engine instance in our GCP project.
121127

122-
### 2. Apply the Compute Engine resources to the admin cluster. **⚠️ Note** - this demo shows applying the cloud-hosted KRM resources manually with kubectl, due to an ongoing bug between Config Sync and Config Connector. But in an ideal scenario, we use Config Sync to sync the Config Connector KRM just like we did policies.
128+
### 2. Apply the Compute Engine resources to the admin cluster.
123129

124130
```
125131
kubectx cymbal-admin
@@ -154,7 +160,9 @@ iamserviceaccount.iam.cnrm.cloud.google.com/inst-dep-cloudmachine 5m58s True
154160

155161
Note - it may take a few minutes for the resources to be created. In the meantime, you may see `UpdateFailed` or `DependencyNotReady`. This is expected.
156162

157-
### 4. **Open the Cloud Console and navigate to Compute Engine > VM Instances. Filter on `name:secadmin`. You should see the new GCE instance in the list.**
163+
### 4. **Open the Cloud Console and navigate to [Compute Engine > VM Instances](https://console.cloud.google.com/compute/instances).
164+
165+
Filter on `name:secadmin`. You should see the new GCE instance in the list.**
158166

159167
![screenshots](screenshots/secadmin-gce-console.png)
160168

5-hosted-resources/partB-cloud-policies.md

+29-14
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export PROJECT_ID=<your-project-id>
2121
### 2. **View the mock transaction dataset.** This is a 1000-line CSV file, whose fields mimic the data currently stored in the Cloud SQL `ledger_db` today.
2222

2323
```
24-
head bigquery/cymbal-mock-transactions.csv
24+
cat bigquery/cymbal-mock-transactions.csv
2525
```
2626

27-
Expected output:
27+
Expected output (truncated):
2828

2929
```
3030
transaction_id,from_account,to_account,amount,timestamp,user_agent
@@ -39,7 +39,9 @@ transaction_id,from_account,to_account,amount,timestamp,user_agent
3939
9,145870222,311667375,$39.17,4/15/2021,Chrome/51.0.2704.103
4040
```
4141

42-
### 3. **Verify that you have the gsutil tool installed** - this comes bundled with the gcloud command. [Install the tool](https://cloud.google.com/storage/docs/gsutil_install) if it's not in your PATH.
42+
### 3. **Verify that you have the gsutil tool installed** - this comes bundled with the gcloud command.
43+
44+
[Install the tool](https://cloud.google.com/storage/docs/gsutil_install) if it's not in your PATH.
4345

4446
```
4547
gsutil version
@@ -48,7 +50,7 @@ gsutil version
4850
Expected output:
4951

5052
```
51-
gsutil version: 4.61
53+
gsutil version: 4.64
5254
```
5355

5456
### 4. **Create a Cloud Storage bucket in your project, called `datasets`.**
@@ -60,7 +62,7 @@ gsutil mb -c standard gs://$PROJECT_ID-datasets
6062
Expected output:
6163

6264
```
63-
Creating gs://krm-test-5-datasets/...
65+
Creating gs://krm-test11-datasets/...
6466
```
6567

6668
### 5. **Upload the mock transaction data to Cloud Storage.**
@@ -85,13 +87,11 @@ cat bigquery/mock-dataset.yaml
8587

8688
Expected output:
8789

88-
```
90+
```YAML
8991
apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
9092
kind: BigQueryJob
9193
metadata:
9294
name: cymbal-mock-load-job
93-
annotations:
94-
configsync.gke.io/cluster-name-selector: cymbal-admin
9595
spec:
9696
location: "US"
9797
jobTimeoutMs: "600000"
@@ -120,17 +120,13 @@ apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
120120
kind: BigQueryDataset
121121
metadata:
122122
name: cymbalmockdataset
123-
annotations:
124-
configsync.gke.io/cluster-name-selector: cymbal-admin
125123
spec:
126124
friendlyName: cymbal-mock-dataset
127125
---
128126
apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
129127
kind: BigQueryTable
130128
metadata:
131129
name: cymbalmocktable
132-
annotations:
133-
configsync.gke.io/cluster-name-selector: cymbal-admin
134130
spec:
135131
friendlyName: cymbal-mock-table
136132
datasetRef:
@@ -189,14 +185,15 @@ Now let's come back to the restrictions we outlined at the beginning of this sec
189185
190186
This file defines a constraint template for `BigQueryDatasetAllowName`, and a constraint of type `BigQueryDatasetAllowName`, which together allow only one BigQuery dataset in the policy repo.
191187
188+
View the custom Constraint Template:
189+
192190
```
193191
cat bigquery/constraint-template.yaml
194-
cat bigquery/constraint.yaml
195192
```
196193
197194
Expected output:
198195
199-
```
196+
```YAML
200197
apiVersion: templates.gatekeeper.sh/v1beta1
201198
kind: ConstraintTemplate
202199
metadata:
@@ -228,6 +225,24 @@ spec:
228225
allowedName: cymbalmockdataset
229226
```
230227

228+
View the Constraint, using the custom Constraint Template:
229+
230+
```
231+
cat bigquery/constraint.yaml
232+
```
233+
234+
Expected output:
235+
236+
```YAML
237+
apiVersion: constraints.gatekeeper.sh/v1beta1
238+
kind: BigQueryDatasetAllowName
239+
metadata:
240+
name: bigquery-allow-mock-only
241+
spec:
242+
parameters:
243+
allowedName: cymbalmockdatase
244+
```
245+
231246
### 12. **Apply the Constraint and Constraint Template** to the admin cluster.
232247
233248
```

5-hosted-resources/partC-existing-resources.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ config-connector version
1414
Expected output:
1515

1616
```
17-
1.46.0
17+
1.53.0
1818
```
1919

2020
### 2. **View the Cloud SQL KRM export script.**
2121

22-
This script generates static KRM resource files (YAML) for the Cloud SQL development database. (Although these steps only show KRM for the development DB, we could do the same for the staging and production databases as well.)
22+
This script generates static KRM resource files (YAML) for the Cloud SQL development database.
23+
24+
**Note**: Although these steps only show KRM for the development DB, we could do the same for the staging and production databases as well.
2325

2426
```
2527
cat cloudsql/generate-cloudsql-krm.sh
@@ -118,11 +120,12 @@ spec:
118120
resourceID: ledger-db
119121
```
120122

121-
These KRM files represent the live state of your Cloud SQL resources, originally created using Terraform. (You will see your PROJECT_ID next to `cnrm.cloud.google.com/project-id`.)
123+
These KRM files represent the live state of your Cloud SQL resources, originally created using Terraform. (You should see your PROJECT_ID next to `cnrm.cloud.google.com/project-id`.)
122124

123125
### 5. **Apply the Cloud SQL KRM resources to the cymbal-admin cluster.**
124126

125127
```
128+
kubectx cymbal-admin
126129
kubectl apply -f cloudsql/projects/$PROJECT_ID/SQLInstance/us-east1/cymbal-dev.yaml
127130
kubectl apply -f cloudsql/projects/$PROJECT_ID/SQLInstance/cymbal-dev/SQLDatabase/accounts-db.yaml
128131
kubectl apply -f cloudsql/projects/$PROJECT_ID/SQLInstance/cymbal-dev/SQLDatabase/ledger-db.yaml
@@ -157,7 +160,7 @@ NAME AGE READY STATUS STAT
157160
sqlinstance.sql.cnrm.cloud.google.com/cymbal-dev 42s True UpToDate 10s
158161
```
159162

160-
### 7. **Open the Cloud Console and navigate to Cloud SQL**.
163+
### 7. **Open the Cloud Console and [navigate to Cloud SQL](https://console.cloud.google.com/sql)**.
161164

162165
Notice how in the list, the `cymbal-dev` cluster now has a new label, `managed-by-cnrm: true`. This indicates that this SQL Instance is now under the management umbrella of Config Connector.
163166

@@ -178,24 +181,25 @@ Notice how in the list, the `cymbal-dev` cluster now has a new label, `managed-b
178181

179182
## Wrap-up
180183

181-
If you made it this far, great work - you just completed several challenging demos that explored the Kubernetes Resource Model with multiple angles, developer personas, products, and tools.
184+
If you made it this far, **great work**! You just completed several demos that explored the Kubernetes Resource Model with multiple developer personas, products, and tools in mind.
182185

183186
Let's summarize the key takeaways from all 5 demos:
184187

185188
- **Building a platform is hard**, especially in the cloud, especially when you have multiple Kubernetes clusters in play, on top of hosted resources.
186-
- **KRM is one way to manage your Cloud and Kubernetes config**, but it's not the only way - Demo 1 showed us how to do it with Terraform.
187189
- KRM is a great way to manage resources because Kubernetes is constantly running a **control loop** to make sure your **desired** state matches the **actual** cluster state. We saw this in action both for core Kubernetes API resources (Demo 2 / for instance, Deployments that keep Pods alive) and hosted Cloud resources (Demo 5 / via Config Connector)
188190
- **KRM promotes a "GitOps" model** where you keep all your configuration in Git, and sync it down to multiple clusters at once.
189191
- Policy Controller, together with Config Sync, allow you to impose custom policies on your KRM resources, both at deploy-time and during CI/CD (Demo 4). These **policies allow you to set fine-grained controls** on different resource types, to ensure compliance within your org.
190192
- **KRM / the Kubernetes API can lifecycle resources that run outside a Kubernetes cluster.** We saw how Config Connector, running inside the admin cluster, created and updated resources in Google Cloud.
193+
- **KRM is one way to manage your Cloud and Kubernetes resources**, but it's not the only way - for instance, we set up the initial demo environment with Terraform in part 1. The benefit of putting more and more resources in a KRM format is that you have a single language and toolchain for your infrastructure, in and outside of Kubernetes.
194+
191195

192-
Hopefully you learned a thing or two from these demos- really, we've only just scratched the surface of what KRM can do. All the "learn more" links across Parts 1-5 are available in the [README of this repo](/README.md).
196+
Hopefully you learned a thing or two from these demos- really, we've only just scratched the surface of what KRM can do.
193197

194-
And another set of resources to learn more about KRM, its design principles, and other helpful tools, see: **https://github.com/askmeegs/learn-krm**.
198+
For a list of additional resources to learn the Kubernetes Resource Model, check out: **https://github.com/askmeegs/learn-krm**.
195199

196200
## ⭐️ We'd love your feedback! ⭐️
197201

198-
### 🗳 [If you have a moment, please fill out this short survey](https://forms.gle/pUX2DPW9fxgDMwEw8) to share your thoughts on this demo! Thank you!
202+
### 🗳 [If you have a moment, please fill out this short survey](https://forms.gle/pUX2DPW9fxgDMwEw8) to share your thoughts on these demos. Thank you!
199203

200204
## Cleaning up
201205

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
applySpecVersion: 1
2+
spec:
3+
configSync:
4+
enabled: false
5+
sourceFormat: unstructured
6+
syncRepo: https://github.com/GITHUB_USERNAME/cymbalbank-policy
7+
syncBranch: main
8+
secretType: none
9+
policyDir: /
10+
policyController:
11+
enabled: true

5-hosted-resources/setup-config-connector.sh

+29-27
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,46 @@ fi
99
gcloud config set project $PROJECT_ID
1010
export SERVICE_ACCOUNT_NAME="cymbal-admin-kcc"
1111

12-
echo "☁️ Creating a Google Service Account (GSA) for Config Connector..."
13-
gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME
14-
15-
echo "☁️ Granting the GSA cloud resource management permissions..."
16-
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
17-
--member="serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
18-
--role="roles/owner"
19-
20-
echo "☁️ Connecting your Google Service Account to the Kubernetes Service Account (KSA) that Config Connector uses..."
21-
gcloud iam service-accounts add-iam-policy-binding \
22-
cymbal-admin-kcc@$PROJECT_ID.iam.gserviceaccount.com \
23-
--member="serviceAccount:$PROJECT_ID.svc.id.goog[cnrm-system/cnrm-controller-manager]" \
24-
--role="roles/iam.workloadIdentityUser"
25-
26-
# Populate configconnector.yaml
27-
echo "☁️ Populating and deploying configconnector.yaml with your GSA info..."
28-
sed -i "s/PROJECT_ID/$PROJECT_ID/g" configconnector.yaml
12+
kcc_project_setup() {
13+
echo "☁️ Creating a Google Service Account (GSA) for Config Connector..."
14+
gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME
15+
16+
echo "☁️ Granting the GSA cloud resource management permissions..."
17+
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
18+
--member="serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
19+
--role="roles/owner"
20+
21+
echo "☁️ Connecting your Google Service Account to the Kubernetes Service Account (KSA) that Config Connector uses..."
22+
gcloud iam service-accounts add-iam-policy-binding \
23+
cymbal-admin-kcc@$PROJECT_ID.iam.gserviceaccount.com \
24+
--member="serviceAccount:$PROJECT_ID.svc.id.goog[cnrm-system/cnrm-controller-manager]" \
25+
--role="roles/iam.workloadIdentityUser"
26+
}
2927

28+
uninstall_config_sync() {
29+
CLUSTER_NAME=$1
30+
CLUSTER_ZONE=$2
31+
echo "☸️ Uninstalling Config Sync and Policy Controller: $CLUSTER_NAME, zone: $CLUSTER_ZONE"
32+
gcloud alpha container hub config-management apply \
33+
--membership=$CLUSTER_NAME \
34+
--config=remove-cs-spec.yaml \
35+
--project=$PROJECT_ID
36+
}
3037

31-
install_kcc () {
38+
install_config_connector () {
3239
CLUSTER_NAME=$1
3340
CLUSTER_ZONE=$2
34-
echo "☸️ Installing Config Connector: $CLUSTER_NAME, zone: $CLUSTER_ZONE" \
41+
echo "☸️ Installing Config Connector: $CLUSTER_NAME, zone: $CLUSTER_ZONE"
3542

3643
kubectx $CLUSTER_NAME
3744

38-
# Apply configconnector.yaml
39-
echo "☁️ Installing the Config Connector controller..."
4045
kubectl apply -f configconnector.yaml
4146
kubectl annotate namespace default cnrm.cloud.google.com/project-id=$PROJECT_ID
4247
}
4348

44-
# Note - due to an ongoing bug, Config Sync and Config Connector can't be installed
45-
# on GKE at the same time. So dev/staging/prod have Config Sync, and admin has config connector.
4649

47-
# install_kcc "cymbal-dev" "us-east1-c"
48-
# install_kcc "cymbal-staging" "us-central1-a"
49-
# install_kcc "cymbal-prod" "us-west1-a"
50-
install_kcc "cymbal-admin" "us-central1-f"
50+
kcc_project_setup
51+
uninstall_config_sync "cymbal-admin" "us-central1-f"
52+
install_config_connector "cymbal-admin" "us-central1-f"
5153

5254
echo "✅ Finished installing Config Connector on the admin cluster."

cleanup.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ echo "🗑 Deleting Config Connector-managed resources (Compute Engine, BigQuery
2626
kubectx cymbal-admin
2727
kubectl delete -f 5-hosted-resources/bigquery/mock-dataset.yaml
2828
kubectl delete -f 5-hosted-resources/compute-engine/instance.yaml
29-
kubectl delete -f cloudsql/projects/$PROJECT_ID/SQLInstance/us-east1/cymbal-dev.yaml
30-
kubectl delete -f cloudsql/projects/$PROJECT_ID/SQLInstance/cymbal-dev/SQLDatabase/accounts-db.yaml
31-
kubectl delete -f cloudsql/projects/$PROJECT_ID/SQLInstance/cymbal-dev/SQLDatabase/ledger-db.yaml
29+
kubectl delete -f 5-hosted-resources/cloudsql/projects/$PROJECT_ID/SQLInstance/us-east1/cymbal-dev.yaml
30+
kubectl delete -f 5-hosted-resources/cloudsql/projects/$PROJECT_ID/SQLInstance/cymbal-dev/SQLDatabase/accounts-db.yaml
31+
kubectl delete -f 5-hosted-resources/cloudsql/projects/$PROJECT_ID/SQLInstance/cymbal-dev/SQLDatabase/ledger-db.yaml
3232

3333
echo "💤 Sleeping 30 seconds to allow Config Connector to delete Cloud Resources..."
3434
sleep 30
@@ -46,4 +46,4 @@ gcloud iam service-accounts delete cymbal-gsa@$PROJECT_ID.iam.gserviceaccount.co
4646
# Terraform destroy (GKE clusters, Git repos, Cloud Build permissions, Cloud SQL databases)
4747
echo "🗑 Running terraform destroy to remove GKE clusters, Cloud SQL databases..."
4848
cd 1-setup/
49-
terraform destroy
49+
terraform destroy -var-file="base-env/terraform.tfvars" --auto-approve base-env

0 commit comments

Comments
 (0)