Skip to content
This repository was archived by the owner on Sep 13, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions cloudbuild.gke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,26 @@ steps:
args: ['push', 'gcr.io/$PROJECT_ID/mysql']
waitFor: ['build db']

- id: 'kustomize build'
name: 'gcr.io/$PROJECT_ID/kustomize:latest'
entrypoint: 'bash'
args:
- '-c'
- |
# update images in k8s config to point to project's container registry
kustomize edit set image USER-REPO/web=gcr.io/$PROJECT_ID/web:latest
kustomize edit set image USER-REPO/mysql=gcr.io/$PROJECT_ID/mysql:latest
# save output to _config.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! One question (note that I'm not very familiar with kustomize): is it possible to overwrite the configs in place? If we could do that, we wouldn't have to save a new file. Not a big deal of course but it would be a little cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as far as I can tell unfortunately. kustomize buildcan be used in a couple ways:
kustomize build . : prints output
kustomize build . > temp.yaml : save output to temp
kustomize build . | kubectl apply -f - apply output

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kustomize cloud builder has kubectl but I think it would make it harder to follow because it would require some extra env variables or gcloud get-credentials command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flipping the script! I just learned that kubectl now has kustomize built-in. If I read this correctly, we can patch the config and deploy the app in one command. I haven't tried it yet, though, and IDK if cloud-builders has a new enough version of kubectl for this to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! will look into it, there might be a version issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cloud-builders uses kubectl gcloud component which is 1.11
https://cloud.google.com/sdk/docs/release-notes

Google Kubernetes Engine kubectl is updated to 1.11.9. Addresses security vulnerability: CVE-2019-1002101.

https://github.com/GoogleCloudPlatform/cloud-builders/blob/master/kubectl/Dockerfile

RUN /builder/google-cloud-sdk/bin/gcloud -q components install kubectl

kustomize build . > _config.yaml
# print to console
cat _config.yaml
dir: 'k8s'
waitFor: ['-']

- id: 'deploy to staging'
name: 'gcr.io/cloud-builders/kubectl'
args: ['apply', '-f', 'k8s/', '--namespace=test-$BUILD_ID']
waitFor: ['push web','push db']
args: ['apply', '-f', 'k8s/_config.yaml', '--namespace=test-$BUILD_ID']
waitFor: ['push web','push db', 'kustomize build']

- id: 'get endpoint'
name: 'gcr.io/cloud-builders/kubectl'
Expand Down
2 changes: 1 addition & 1 deletion k8s/db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
containers:
- name: mysql
# Dev TODO: add your project id here
image: gcr.io/PROJECT-ID/mysql:latest
image: USER-REPO/mysql:latest
env:
- name: MYSQL_ROOT_PASSWORD
value: "password"
Expand Down
7 changes: 7 additions & 0 deletions k8s/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- db.yaml
- web.yaml
- db-service.yaml
- web-service.yaml
File renamed without changes.
2 changes: 1 addition & 1 deletion k8s/web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
containers:
- name: web
# Dev TODO: add your project id here
image: gcr.io/PROJECT-ID/web:latest
image: USER-REPO/web:latest
env:
- name: DB_HOST
value: cookieshop-db
Expand Down