Simple Continuous Deployment on GKE with gke_ci

May 18, 2017. Filed under k8s 4 gke 2 deployment 2

Last I spent some time learning about the Google Container Engine, and was almost able to get a full continuous deployment pipeline working, but it was missing the last mile from the container building to it actually getting deployed, so I wrote up a very small proof of concept called gke_ci and put it up on Github.

It's quite, quite basic, and works by subscribing to the cloud_builds PubSub topic, and then calling the Kubernetes API to update the deployed version of all existing deployments that use that container. There are so few container builds, that I discover all deployments every time there is a successful build, so there is no "setup" process to add another service, and it'll automatically work for new stuff.

I'm running gke_ci in a deployment with one instance, and interestingly it actually upgrades itself! Using the same logic as for other builds: when it sees a new build for its container, it'll detect its deployment uses that container, and trigger an upgrade. Kubernetes will then spin down the current container and spin up a new version, with builds remaining queued in PubSub until it comes back up and resumes its duties.

Altogether, this gives me a ~5 minute deployment from push to full rollout on my small cluster, and doesn't require active watching from me (rolling rollouts catch vast majority of issues I've found), although I will still need to add a build step that runs tests (should be easy in Container Builder if I'm willing to polute the container a bit), as well as send notifications for failed builds (easy to add togke_ci itself since it already listens to the cloud_builds queue, or could add another simple utility with a new subscription).