I had originally planned just to use cloud functions for some of the work referred to in Google cloud platform
, but since I’m running a Kubernetes cluster anyway, making that cluster scalable to deal with cloud run functions firstly keeps everything inside the cluster so there’s no need to expose anything externally, and secondly gives me an excuse to learn about Cloud Run. However, as it turned out, there are a couple of restrictions with this that made cloud run not work for me. In the end I just decided to run this as a regular app on my Kubernetes cluster. Why ?
- I wanted to use pubsub, and you can certainly do that with cloud run. However, you can only do push notification, which involves running an express server in the app to listen for those calls.
- The endpoint for pubsub to regular cloud run provides an https endpoint, but its a web.app firebase style address, blocked by some apis. The same thing applied to cloud functions. I fiddled around to assign my own address via my own ingress as an endpoint, but the benefit of cloud run was quickly disappearing.
In any case, here’s what you need to do to get your kubernetes cluster cloud run ready.
What is cloud run and what’s the difference with cloud functions
Cloud run is a serverless way of running stateless containers, which can be doing anything that can be containerized, and can be run in your own Kubernetes container (or even eventually other providers clouds), whereas cloud functions are deployed as event invoked functions and are limited by the languages the platform support.
Getting your Kubernetes cluster ready for cloud functions
As your solution becomes more complex with a pathchwork of these microservices needed to be glued together, often across different cloud providers) and the business of authentication and interservice communication just becomes just too complex. Google announced a product called Anthos at Next2019 to do that. So components of that needed to be able to use cloud run on your cluster. They call these GKE ‘addons’, so to help with that we need to enable that and some additional apis. I’m assuming you already have a cluster runing, ready to update.
These are beta feature so you’ll need to some extra gcloud components
gcloud components update
gcloud components install beta
gcloud beta container clusters update
you’ll also need to enable these apis
gcloud services enable container.googleapis.com containerregistry.googleapis.com cloudbuild.googleapis.com
and if you haven’t already done it, enable logging too. You’ll need that later.
gcloud container clusters update YOURCLUSTERNAME --logging-service logging.googleapis.com
I believe most of that can be done from somewhere in the cloud console UI, but it’s better to create a script record of what you’ve dobe so you can both review and repeat it. In any case, your cluster settings (under Anthos is edit cluster) should look something like this now if you go off to the console UI
and that’s it – I’m ready to deploy my first cloud run container.