GKE: running microservices in Go

Fermin Blanco
2 min readApr 14, 2022

Since running applications inside containers and abstracting away infrastructure provisioning from application development process has become way too complex, I am spicing up a guide to ease this experience for you.

We’ll be using docker for infrastructure provisioning, kubernetes for container management, Go for backend development and GKE as a cloud kubernetes service

GKE cluster

Google Kubernetes Engine a.k.a GKE

GKE is a full-fledged service that allows deploying docker images to kubernetes engine that can scale and managed with easy.

Creating a cluster that will host the Go service
Getting credential for making operations in the cluster

Our Dockerfile will look like the above:

Dockerfile

From could use — platform flag to specify the platform of the image

And a basic http service will be written as follow:

Artifact registry

We need a way to store our binary images in a way to make it easy to deploy to a Cloud platform. GCP provide artifact registry that replaces Container registry.

Creating a docker repo in Artifact registry

to build multi-arch images, link them together with a manifest file, and push them all to a registry using a single command

Docker building and pushing multi-arch image to Artifact registry

The reason behind building and pushing to artifact registry all in the same command is that, if you do not supply — push parameter, docker will not attempt to generate the manifest and push it to a docker registry. On the other hand, a local docker repository can’t serve multi-arch images behind one manifest. Therefore, the built result will be simply discarded.

BUT life is not easy, you know? and developing this microservice was not the exception

Leverage multi-CPU architecture support

Written this tiny service points me to a interesting problem, building the Image into my local machine that has different kernel architecture as in the cloud platform virtual machine instance.

In general, you can’t run docker images that target a different processor architecture than your hose system. However, you can run Linux architectures like ARM64 on Windows using Docker Desktop. Docker Desktop uses the qemu-static emulator to make this cross-architecture emulation completely seamless!

So it come to my existence buildx. A tool for multi-architecture support.

--

--