This repo demostrates Kubernetes CI/CD with Google Cloud devops tools Google Cloud Deploy, Cloud Build, and Artifact Registry. The example app is based on a simple Python Flask example app named "Population Stats" and uses Kustomize overlays for manifest generation.
This demo relies on you making git check-ins to simulate a developer workflow. Fork this repo, or otherwise copy it into your own Github repo.
- In
clouddeploy.yaml
, replaceproject-id-here
with your actual project for each of the three targets.
Bootstrap scripts are in the bootstrap
folder.
The init.sh
script is provided to bootstrap much of the configuration setup. You'll still need to do some steps manually after this script runs though.
- In
init.sh
, replace project-id-here with your Google Cloud project-id on line 3. - Run
. ./bootstrap/init.sh
- Verify that the Google Cloud Deploy pipeline was created in Google Cloud Deploy UI
- Setup a Cloud Build trigger for your repo
- Navigate to Cloud Build triggers page
- Follow the docs and create a Github App connected repo and trigger.
You'll need GKE clusters to deploy out to as part of the demo. This repo refers to three clusters:
- testcluster
- stagingcluster
- productcluster
If you have/want different cluster names update cluster definitions in the gke-cluster-init.sh bash script and in clouddeploy.yaml
To create the clusters, edit bootstrap/gke-cluster-init.sh
:
- Replace
project-id-here
with your project-id on line 3. - Run
. ./bootstrap/gke-cluster-init.sh
You must give Cloud Build explicit permission to trigger a Cloud Deploy release.
- Read the docs
- Navigate to IAM and locate your Cloud Build service account
- Add these two roles
- Cloud Deploy Releaser
- Service Account User
The demo is very simple at this stage.
- User commits a change the main branch of the repo
- Cloud Build is automatically triggered, which:
- builds and pushes impages to Artifact Registry
- creates a Cloud Deploy release in the pipeline
- User then navigates to Cloud Deploy UI and shows promotion events:
- test cluster to staging clusters
- staging cluster to product cluster, with approval gate
To remove the three running GKE clusters, edit bootstrap/gke-cluster-delete.sh
:
- Replace
project-id-here
with your project-id on line 3. - Run
. ./bootstrap/gke-cluster-delete.sh
To run this app locally, start minikube or some other local k8s framework and from the root of the repo run:
skaffold dev
The default skaffold settings use the "dev" customer overlay.
Once running, you can make file changes and observe the rebuilding of the container and redeployment.
To test the staging overlays/profile:
skaffold run --profile staging
To test the staging overlays/profile:
skaffold run --profile prod
Google Cloud Shell provides a free environment in which to play with these files:
Simple web app that pulls population data based on U.S. address queries. Note, other countries are currently not supported.
Population data gathered from the U.S. Census Bureau Population Estimate API.
Feedback and contributions welcomed.